MySql创建数据表

创建表需要的三要素

1、表名

2、表字段

3、表字段类型

语法

create table tableName (column_name column_type);

实例

create table test (

  id int not null auto_increment,

  name varchar(20) not null,

  primary key (id)

)

实例解析:

如果你不想要字段为空,则设置字段的属性为not null 如果插入空值 会报错

auto_increment 字段自增长 一般用于主键 每次加1

primary key 设置主键 多个字段设置的话 逗号分开

猜你喜欢

转载自wangduorong.iteye.com/blog/2299105