数据库主要关键字

一、约束关键字
1.primary key 主键

主键约束字段不能为空,不能重复,一张表只能有一个主键

2.foreign key 外键

eg:foreign key(Sno)
一般会和references一起出现,如下:

3.references

A表Sno需要B表Sno数据,结合外键
eg:
foreign key(Sno)  references B(Sno),

4.unique 唯一键
5.check 约束

eg:
check(Ssex=‘男’ or Ssex='女’)
check(age>=1 and age<=100)
此处也可以用 age between ** and**
not between ** and **

6.default 默认值

未添加数据时的默认值

7.not null

不能为空

8.indentity(种子值,增量值) 自增
9.zerofill 若长度未达到规定,自动在字段前填充0
二、增删查改关键字
1.insert 插入

insert into 表名(列名以逗号隔开) values(以逗号隔开,字符型带‘’);
eg:
insert into Student(Sno,Ssex) values(10,'男');

2.update 修改

1.update 表名  set  将要修改的列名=修改的数据;    将表中此列所有数据都修改
2.update 表名  set  将要修改的列名=修改的数据   where 列名=?;   此列中列名=?的修改数据
eg:
update goods set price=price+10;
update orders set quantity=5  where customerid=2;

3.delete 删除

delete from orders where customerid=2;  删除了orders表中customerid=2的记录

4.select 查询
(1)

1.select  需要查找的列名;(>=2以逗号隔开)  from 表名;
2.select*  from 表名;    查找此表所有数据
3.select 2014-sage from student;    查询结果是2014-sage的值
4.select ‘year of birth:’,2014-sage from student;   ''内的内容单独作为一列原样输出
5.select sname NAME from student;   将原列名sname改为NAME

(2)distinct消除重复

eg:
select distinct sno from sc;  消除sc表中sno重复行

(3)where 查询条件

在这里插入代码片

(4)lower 小写

eg:
select lower sdept from student; 将student表sdept列以小写显示

(5)like 和not like

若like后不含通配符,则可以取代= 
eg:
select* from student where sno like '2015486';  
若含有通配符(%:a%b y以a开头,b结尾任意长度的字符串,和_:a_b以a开头 b结尾的长度为3的字符串)
select sname from student  wher sname like '_阳%'; 查找名字中第二个字为阳的学生姓名  

(6)as

在这里插入代码片

(7)in 和 not in

eg:
select sname from student  where sdept in('SC'); 查找student表中sdept列中在SC系的学生名字
与之对应 not in

(8)escape’’

跟在\后的_  只代表_  不作为通配符

(9)order by 列名 asc升序 /desc降序
(10)group by 列名 按值分组

  • 13
    点赞
  • 82
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值