“无意中发现了一个巨牛的人工智能教程,忍不住分享一下给大家。教程不仅是零基础,通俗易懂,而且非常风趣幽默,像看小说一样!觉得太牛了,所以分享给大家。点这里可以跳转到教程。”。
目录
1、建库规范
2、建表规范
3、常用建表语句
4、建表约束
3、常用建表语句
1、最简单的:
CREATE TABLE t1(
id int not null,
name char(20)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
2、带主键的:
a:
CREATE TABLE t1(
id int not null primary key,
name char(20)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
b:复合主键
CREATE TABLE t1(
id int not null,
name char(20),
primary key (id,name)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
3、带默认值的:
CREATE TABLE t1(
id int not null default 0 primary key,
name char(20) default '1'
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
4、带自增列:
CREATE TABLE t1(
id int not null auto_increment,
name VARCHAR(45) null,
age INT NULL,
primary key (id,name)
)ENGINE=InnoDB DEFAULT CHARSET=utf8;
SELECT * from t1;
INSERT INTO t1(name) values ('yh')
INSERT INTO t1(name , age) values ('yh',30)
4、建表约束
1)默认为空
2)默认不能为空
3)表格字段有注释
drop table house_prices;
CREATE TABLE house_prices(
Home int not null COMMENT '房子编号',
Price int DEFAULT NULL COMMENT '价格',
SqFt int DEFAULT NULL COMMENT '总面积',
Bedrooms int DEFAULT NULL COMMENT '卧室数',
Bathrooms int DEFAULT NULL COMMENT '卫生间数',
Neighborhood VARCHAR(45) DEFAULT NULL COMMENT '朝向',
primary key (Home)
)ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT '房子一览表';