让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FirstName varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(FirstName) values('Chris'); mysql> insert into DemoTable(FirstName) values('Adam'); mysql> insert into DemoTable(FirstName) values('John'); mysql> insert into DemoTable(FirstName) values('David'); mysql> insert into DemoTable(FirstName) values('Mike'); mysql> insert into DemoTable(FirstName) values('Carol'); mysql> insert into DemoTable(FirstName) values('Sam');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+-----------+ | Id | FirstName | +----+-----------+ | 1 | Chris | | 2 | Adam | | 3 | John | | 4 | David | | 5 | Mike | | 6 | Carol | | 7 | Sam | +----+-----------+ 7 rows in set (0.00 sec)
这是查询记录顺序并删除n行的查询-
mysql> delete from DemoTable order by FirstName asc limit 4;
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+-----------+ | Id | FirstName | +----+-----------+ | 3 | John | | 5 | Mike | | 7 | Sam | +----+-----------+ 3 rows in set (0.00 sec)