创建表的语法:
create table [if not exisit] `tableNane`(
`字段名` 数据类型 [字段属性] [完整性约束] [索引] [注释],
...
);
示例:
primary key: 完整性约束(主键:唯一的,非空的)
create table if not exisit `Student`(
`StuNumber` int primary key,
Name char(20),
...
);
MySQL中的数据类型常用数据类型
UNSIGNED 标识为无符号数
ZEROFILL属性位数(宽度)不足时以0填充
如果某个字段指定了ZEROFILL属性,将自动添加UNSIGEND属性
示例,创建表查询数据
# 选择数据库
use mydatabases;
# 创建表
create table if not exists `tb_type`(
`sid` int(4) zerofill
);
# 连续插入单条数据
insert into `tb_type` (`sid`) value (1);
insert into `tb_type` (`sid`) value (12);
insert into `tb_type` (`sid`) value (134);
insert into `tb_type` (`sid`) value (1234);
# 从tb_type表中查询所有数据
select * from `tb_type`;
运行结果:sid
0001 # 数位小于宽度 以0填充
0012
0123
1234 # 数位大于等于宽度,以实际位数显示