时间:2021-07-01 10:21:17 帮助过:2人阅读
Demo:
1 CREATE TABLE test( 2 username VARCHAR(20), 3 age TINYINT UNSIGNED, 4 salary FLOAT(8,2) INSIGNED 5 );View Code
demo中的UNSIGNED表示无符号
查看数据表结构:SHOW COLUMNS FROM 数据表名
Demo:
INSERT test2 VALUES(‘GZC‘,21,999999.99); INSERT test2(username,age,salary) VALUES(‘gzc‘,21,1);View Code
创建表时可设置某一列的属性是否允许为空
demo:
1 CREATE TABLE test3( 2 username VARCHAR(20) NOT NULL, 3 age TINYINT UNSIGNED 4 );View Code
数据列默认允许为NULL
Demo:
CREATE TABLE test3( id TINYINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, username CHAR(20) );View Code
CREATE TABLE test4( id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(20) NOT NULL UNIQUE KEY, age TINYINT UNSIGNED );View Code
当插入记录时,如果没有明确为字段赋值,则自动赋予默认值
Demo:
1 CREATE TABLE test5( 2 id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY, 3 username VARCHAR(20) NOT NULL UNIQUE KEY 4 sex ENUM(‘1‘,‘2‘,‘3‘) DEFAULT ‘3‘ 5 );View Code