Home > Database > Mysql Tutorial > 09. 约束与索引的联系

09. 约束与索引的联系

WBOY
Release: 2016-06-07 17:37:07
Original
1411 people have browsed it

之所以把约束和索引放到一起来看,主要是因为主键约束和唯一键约束,它们会自动创建一个对应的索引,先分别看下数据库中的几个约束。 一 约束 在关系型数据库里,通常有5种约束,示例如下: use tempdb s(sid varchar ( 20 ),sname varchar ( 20 ),ssex ssex

之所以把约束和索引放到一起来看,主要是因为主键约束和唯一键约束,它们会自动创建一个对应的索引,,先分别看下数据库中的几个约束。

一 约束

在关系型数据库里,通常有5种约束,示例如下:

use tempdb s ( sid varchar(20), sname varchar(20), ssex ssex) , sage ), sclass varchar(20) unique, constraint PK_s primary key (sid,sclass) ) create table t ( teacher varchar(20) primary key, sid varchar(20) not null, sclass varchar(20) not null, num int, foreign key(sid,sclass) references s(sid,sclass) )

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template