SQL 必须记住的关键字

来源:互联网 发布:python smtp发送邮件 编辑:程序博客网 时间:2024/06/05 08:41

SQL 必须记住的关键字

 

create table 表名(

id int primary key auto_increment,

username varchar(255) default '跌名' not null

p_id int ,

foreign key(p_id) references 表名(字段名)

)Engine=InnoDB Default charset=utf8;

insert into 表名(字段1,字段2,字段3) values(值1,值2,值3);

insert into 表名values(值1,值2,值3); 此时必须按顺序来

修改表

1 . 添加约束

alter table 表名 add constraint 约束名 primary key(字段名);

2. 修改字段

alter table 表名 change 旧字段名 新字段名 类型 约束 默认 是否为空

alter table user change age age int default 2 not null;

3. 添加外键主键

alter table user change id id int primary key auto_increment;

alter table 表名 add constraint 约束名 foreign key(本表字段名) references 外键表名(外键字段名);

inner join

left join

teacher t left outer join student s

right join

right outer join

full join

full outer

原创粉丝点击