仅显示MySQL中为列设置的默认值
让我们首先创建一个表并设置默认值-
mysql> create table DemoTable803(UserId int DEFAULT 101,UserName varchar(100) DEFAULT 'Chris');
使用insert命令在表中插入一些记录。对于我们不插入的值,默认值将自动设置-
mysql> insert into DemoTable803 values(102,'Chris');mysql> insert into DemoTable803(UserName) values('Mike');
mysql> insert into DemoTable803(UserId) values(103);
mysql> insert into DemoTable803 values();
mysql> insert into DemoTable803 values(110,'Robert');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable803;
这将产生以下输出-
+--------+----------+| UserId | UserName |
+--------+----------+
| 102 | Chris |
| 101 | Mike |
| 103 | Chris |
| 101 | Chris |
| 110 | Robert |
+--------+----------+
5 rows in set (0.00 sec)
以下是仅显示默认值的查询-
mysql> select default(UserId),default(UserName) from DemoTable803 limit 1;
这将产生以下输出-
+-----------------+-------------------+| default(UserId) | default(UserName) |
+-----------------+-------------------+
| 101 | Chris |
+-----------------+-------------------+
1 row in set (0.00 sec)
以上是 仅显示MySQL中为列设置的默认值 的全部内容, 来源链接: utcz.com/z/316826.html