#创建数据库 create database if not exists school; #创建表 create table if not exists student( id int(4) primary key auto_increment, pwd varchar(20) DEFAULT'123456' not NULL, `name` varchar(30) default'匿名' not NULL, sex varchar(2) not null default '男', birthday timestamp, address varchar(100), email varchar(50) ) #创建表 create table if not exists test( coll int(4) ) #设置严格检查模式 set sql_mode='strict_trans_tables'; #创建表tab1,把id设为主键,并且设置自增(默认初始值1,步长1) create table tab1( id int(4) primary key auto_increment, `name` varchar(20) not null ) #创建表tab1,把id设为主键,并且设置自增(将默认值改为100,步长1) create table tab2( id int(4) primary key auto_increment, `name` varchar(20) not null )auto_increment=100; #设置步长 set @@auto_increment_increment=5; #同一个列可以被多个属性修饰,但注意属性的顺序 create table tab3( id int(4) not null default 5 UNSIGNED ) #查看mysql所支持的引擎类型(表类型) show engines; #查看默认引擎 show variables like 'storage_engine'; #设置一列的字符集编码格式 create table a( address char(5) character set gbk ) #设置表的字符集 default charset=utf8 #设置库的字符集 default character set utf8 #重名名表 alter table tab1 rename as table1 #为表添加列 alter table table1 add address varchar(100) default'中国北京'; #修改表 alter table table1 modify address varchar(500) default '朝阳区'; #删除字段 alter table tab2 drop 'id'; #修改列名 alter table table1 change address 地址 varchar(100) default '朝阳区'; #创建表 create table if not exists `subject`( subjectNo int(11) primary key not null comment'课程编号' auto_increment, subjectName varchar(50) comment'课程名称', classHour int(4) comment'学时', gradeID int(4) comment'年级编号' )
8/11 修改表
猜你喜欢
转载自www.cnblogs.com/zeng1997/p/11335862.html
今日推荐
周排行