hooyantsing's Blog

SQL语句

字数统计: 284阅读时长: 1 min
2019/11/18

SQL语句

Oracle表

create table |表名|(

       cid number(4) primary key,

       cname varchar2(100),

);

MySQL表

createtable |表名|(

       cidint,

       cnamevarchar(100),

);

insert into |表名|values(value1,value2,value…);

delete from |表名| where |条件|;

update |表名| set |字段名1|=|改后值|where |条件|;

select *

from |表名1|

left/right join |表名2| on |表名1|.|字段名| = |表名2|.|字段名|

where |条件|

group by |字段名|

order by |字段名| ASC/DESC

自增序列

create sequence s_|表名| start with |起始序号|increment by |每次递增值|;

主键约束

alter table |表名| add constraint pk_|表名|_|字段名|primary key(|字段名|);

外键约束

alter table |本表名| add constraint fk_|本表名|_|本字段|foreign key(|本字段|) references |外表名|(|外字段|);

唯一约束

alter table |表名| add constraint uq_|表名|_|字段名|unique(|字段名|);

非空约束

alter table |表名| modify |字段名| not null;

检查约束 单选

alter table |表名|o add constraint ck_|表名|_|字段名|check(|字段名| in(‘value1’,’value2’));

检查约束 范围

alter table |表名| add constraint ck_|表名|_|字段名|check(|字段名| between valueand VALUE);

删除约束

alter table |表名|drop constraint |约束名|;

删除表

drop table |表名|

CATALOG