🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
`create table [if not exists] 表名(字段1,字段2,----[索引1,索引2,---约束1,约束2,--]) [表选项1,表选项2]` 字段设定形式:字段名:类型[字段属性1,字段属性2,….] 说明: 1,字段名可以自己取 2,类型就是前面所学的数据类型:int,tinyint,float,double,等等 3,字段属性可以有多个,相互之间空格隔开 4,default指定该列的默认值 例如: ~~~ create table tab_shuxing( id int auto_increment primary key, user_name varchar(20) not null unique key, password varchar(48) not null comment, age tinyint default 18, email varchar(50) comment ‘电子邮箱’ }; ~~~ 还有种创建的同时写入数据 ~~~ CREATE TABLE tdb_goods_brands ( brand_id SMALLINT UNSIGNED PRIMARY KEY AUTO_INCREMENT, brand_name VARCHAR(40) NOT NULL ) SELECT brand_name FROM tdb_goods GROUP BY brand_name; ~~~