在 MySQL 中有没有办法在 INSERT 语句中为列命名?
是的,我们可以在 insert 语句中为列命名。让我们首先创建一个表格 -
mysql> create table DemoTable674( StudentId int, StudentFirstName varchar(100), StudentLastName varchar(100) ); Query OK, 0 rows affected (0.82 sec)
使用 insert 命令在表格中插入一些记录 -
mysql> insert into DemoTable674 set StudentId=10,StudentFirstName='John',StudentLastName='Smith'; Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable674 set StudentId=11,StudentFirstName='Carol',StudentLastName='Taylor'; Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable674 set StudentId=12,StudentFirstName='David',StudentLastName='Miller'; Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable674 set StudentId=13,StudentFirstName='Chris',StudentLastName='Brown'; Query OK, 1 row affected (0.53 sec)
使用 select 语句从表格中显示所有记录 -
mysql> select *from DemoTable674;
这将产生以下输出 -
+-----------+------------------+-----------------+ | StudentId | StudentFirstName | StudentLastName | +-----------+------------------+-----------------+ | 10 | John | Smith | | 11 | Carol | Taylor | | 12 | David | Miller | | 13 | Chris | Brown | +-----------+------------------+-----------------+ 4 rows in set (0.00 sec)
广告