让我们首先创建一个表-
mysql> create table DemoTable -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentName varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable(StudentName) values('Chris'); mysql> insert into DemoTable(StudentName) values('Robert'); mysql> insert into DemoTable(StudentName) values('David'); mysql> insert into DemoTable(StudentName) values('Mike');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1 | Chris | | 2 | Robert | | 3 | David | | 4 | Mike | +-----------+-------------+ 4 rows in set (0.00 sec)
这是查询以移动MySQL中现有行的id值的查询-
mysql> update DemoTable set StudentId=StudentId+1000; Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+-------------+ | StudentId | StudentName | +-----------+-------------+ | 1001 | Chris | | 1002 | Robert | | 1003 | David | | 1004 | Mike | +-----------+-------------+ 4 rows in set (0.00 sec)