반응형
이번에는 Delete 를 확인해보겠습니다.
Delete 는 Record 값을 지우기 위해서 사용합니다.
사용 방법은 여러가지가 있습니다.
1. 조건 행 삭제
DELETE > DELETE FROM {TABLE} WHERE COLUMN = {VALUE};
조건에 맞춰서 삭제해보겠습니다.
delete from users where email = 'ryu@test.com';
users 테이블에서 email이 ryu@test.com 인 행을 삭제.
+----+----------+------------------+---------------------+
| id | username | email | created_at |
+----+----------+------------------+---------------------+
| 1 | ryu | ryu@test.com | 2024-03-13 22:14:42 |
| 2 | ryu | kim@test.com | 2024-03-13 22:54:12 |
| 3 | ryu | joe@test.com | 2024-03-13 22:54:12 |
| 4 | ryu | choi@test.com | 2024-03-13 22:54:12 |
| 5 | ryu | ryutest@test.com | 2024-03-14 00:39:07 |
+----+----------+------------------+---------------------+
delete from users where email = 'ryu@test.com';
+----+----------+------------------+---------------------+
| id | username | email | created_at |
+----+----------+------------------+---------------------+
| 2 | ryu | kim@test.com | 2024-03-13 22:54:12 |
| 3 | ryu | joe@test.com | 2024-03-13 22:54:12 |
| 4 | ryu | choi@test.com | 2024-03-13 22:54:12 |
| 5 | ryu | ryutest@test.com | 2024-03-14 00:39:07 |
+----+----------+------------------+---------------------+
2. 전체 데이터 삭제
DELETE > DELETE FROM {TABLE};
+----+----------+------------------+---------------------+
| id | username | email | created_at |
+----+----------+------------------+---------------------+
| 2 | ryu | kim@test.com | 2024-03-13 22:54:12 |
| 3 | ryu | joe@test.com | 2024-03-13 22:54:12 |
| 4 | ryu | choi@test.com | 2024-03-13 22:54:12 |
| 5 | ryu | ryutest@test.com | 2024-03-14 00:39:07 |
+----+----------+------------------+---------------------+
MariaDB [test]> delete from users;
MariaDB [test]> select * from users;
Empty set (0.00 sec)
반응형
'Database' 카테고리의 다른 글
[Database] Auto Increment (0) | 2024.03.18 |
---|---|
[Database] MariaDB - Select, Insert, Update, Delete(4) (0) | 2024.03.18 |
[Database] MariaDB - Select, Insert, Update, Delete(3) (0) | 2024.03.14 |
[Database] MariaDB - Select, Insert, Update, Delete(2) (0) | 2024.03.14 |
[Database] MariaDB - Select, Insert, Update, Delete(1) (0) | 2024.03.14 |