在sql中创建表

#创建表

(如果存在相同名称的表,就把原来的表删除,并创建新表)

drop table if exists xuesheng(表名);

create table xuesheng(

#在表中加入一个新的字段sno
sno varchar(20) not null primary key comment'学号',

#在表中加入一个新的字段
sname varchar(20) not null comment'学生姓名',

#在表中加入一个新的字段
ssex varchar(20) not null comment'学生性别',

#在表中加入一个新的字段
sbirthday datetime comment'学生出生年月',

#在表中加入一个新的字段
class varchar(20) comment'学生所在班级'
);

#假如要创建多个字段,中间用逗号分割,最后一个字段后面不用加,结束时要用分号。

not  null: 不为空,表示该字段不能放“null”这个值。不写,则默认是可以为空

auto_increment:  设定int类型字段的值可以“自增长”,即其值无需“写入”,而会自动获得并增加

此属性必须随同 primary key  或 unique key 一起使用

[primary] key: 设定为主键。是唯一键“加强”:也不能重复并且不能使用null,并且可以作为确定任意一行数据的“关键值”,最常见的类似:where id= 8;  或  where  user_name = ‘zhangsan’;

通常,每个表都应该有个主键,而且大多数表,喜欢使用一个id并自增长类型作为主键。

但:一个表只能设定一个主键。

表中的数据类型:

int;(数值)

datatime;(时间日期)

varchar;(字符串 )

在数据类型后面加小括号里面可以规定数值的长度

原文地址:https://www.cnblogs.com/LQK157/p/8909439.html