sql基础语言总结

一、DDL

1.定义表

create table 表名(

属性1 char(1) constraint 约束名 primary key,

属性2 number constraint 约束名 references 表名(属性名),

属性3 int constraint 约束名 check (属性3>1),

属性4 date not null constraint 约束名 unique,

属性5 varchar(2) check (属性5 in ('男','女')),

属性6 char(1) default('1'),

constraint 约束名 primary key(属性名),

constraint 约束名 foreign key(属性名) references 表名(属性名)

);

2.修改表

#添加属性
alter table 表名 add 属性1 char(1);
#删除属性
alter table 表名 drop column 属性1;
alter table 表名 drop (属性1,属性2);
#修改数据类型,添加新约束
alter table 表名 modify 属性1 char(1);
#添加约束
alter table 表名 add constraint 约束名 [约束];

3.建立索引

create unique index 索引名 on 表名(属性名);

create unique index 索引名 on 表名(属性1 asc,属性2 desc);

二、DML

1.插入数据

#除了数值类型以外,都要加引号
insert into 表名(属性1,属性2,属性3,属性4) 
values (1,2,null,to_date('2023-01-03','yyyy-mm-dd'));

insert into avggrade(cno,avg)
(select cno,avg(grade)
from sc
group by cno
);

2.更新数据

update 表名
set sage=sage+1
where ...;

3.删除数据

delete
from 表名
where ...;

三、SQL

1.简单查询

#结果不重复
select distinct ccredit
from sc order by ccredit desc;

select 2020-sage 'birthday'
from student;
#找出名叫A_B的人
select sname
from student
where sname like 'A【_B' escape '【';

2.连接查询

考完试了,懒得写了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值