먼저 테이블을 생성하겠습니다 -
mysql> create table DemoTable722 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentName varchar(100), StudentAge int ); Query OK, 0 rows affected (1.84 sec)
삽입 명령을 사용하여 테이블에 일부 레코드 삽입 -
mysql> insert into DemoTable722(StudentName,StudentAge) values('Chris Brown',23) ; Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('John Smith',21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('David Miller',22); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('Adam Smith',20); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable722(StudentName,StudentAge) values('Carol Taylor',24); Query OK, 1 row affected (0.39 sec)
select 문을 사용하여 테이블의 모든 레코드 표시 -
mysql> select *from DemoTable722;
그러면 다음과 같은 출력이 생성됩니다. -
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 23 | | 2 | John Smith | 21 | | 3 | David Miller | 22 | | 4 | Adam Smith | 20 | | 5 | Carol Taylor | 24 | +-----------+--------------+------------+ 5 rows in set (0.00 sec)
다음은 MySQL 테이블에서 삭제하는 쿼리입니다. WHERE column equals value AND column2 equals value2 −
mysql> delete from DemoTable722 where StudentId=3 and StudentName='David Miller'; Query OK, 1 row affected (0.21 sec)
테이블 레코드를 다시 한 번 확인합시다 -
mysql> select *from DemoTable722;
그러면 다음과 같은 출력이 생성됩니다. -
+-----------+--------------+------------+ | StudentId | StudentName | StudentAge | +-----------+--------------+------------+ | 1 | Chris Brown | 23 | | 2 | John Smith | 21 | | 4 | Adam Smith | 20 | | 5 | Carol Taylor | 24 | +-----------+--------------+------------+ 4 rows in set (0.00 sec)