create database yuhui;
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)
如果您喜欢我写的博文,读后觉得收获很大,不妨小额赞助我一下,让我有动力继续写出高质量的博文,感谢您的赞赏!微信