mysql数据库学习

mysql中的5大约束。

1. not null ,约束。

    col_a decimal not null

可以使用alter table test111 modify col_a decimal null; 去掉约束。

2. unique 约束

  col_a int unique;

  或者 unique(col_a);

 或者 constraint test_uk unique(col_a, col_b);

alter table test111 add unique(col_a, col_b);

alter table test111 drop index teset3_uk;

3, primary key 主键约束

列级主键约束只能定义一个列。

表级主键可以定义多个列为主键

使用语法同unique一样。

 col_a decimal  primary key 

primary key(col_a);

constraint test_primary primary key(sssss,bbb);

alter table test111 drop primary key;  一个表只能有1个主键

alter table test1111 modify col_c int primary key;

alter table test1111 add primary key (a,b);


注: 自增长列  a int auto_increment

4 foreign key 外键

单列: references pxb(col_a);

组合列:foreign key(col_c) references test111(col_d) on delete cascade;  or  on delete set null; 前者删除主键的时候,自动删除从表中所有的列; 后者设置为null

加上外检名称 constraint test_fk foreign key (col_d) references teacher(col);

定义外键的时候,可以指定 

5. check (emp_salary>0);

6.index 索引。索引可以加速查询速度,一个数据表可以有多个索引。

create index pxb on employ(id,name);

drop index index_name on employ;

mysql 一个表上的索引不同名。  oracle系统中所有表的索引不同名。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值