Mysql database learning-4, integrity constraints

Source: Internet
Author: User

Mysql database learning-4, integrity constraints primary key

create table feng(teamno int not null,playerno int not null,division char(6) not null,primary key(teamno))create table feng(teamno int not null primary key ,playerno int not null,division char(6) not null,)

 

Composite primary key
create table feng(teamno int not null,playerno int not null,division char(6) not null,primary key(teamno,playerno))

 

Alternative key (candidate key)
create table feng(teamno int not null primary key ,playerno int not null,division char(6) not null,unique(playerno))create table feng(teamno int not null primary key ,playerno int not null,division char(6) not null,unique(playerno,division))

 

The foreign key statement (used in innoDB) consists of three parts: 1. The column or column combination is foreign key 2, and the table and column 3 referenced by the foreign key are specified, reference action [cascade (cascade operation), restrict (reject operation), set null (set to null), no action, set default] If no reference action is specified, the default action is
On update restricton delete restrictcreate table feng (teamno int not null primary key, playerno int not null, division char (6) not null, foreign key (division) references othertable (column) on update restrictunique (playerno) check Integrity Constraint create table players (playerno int not null, sex char (1) not null, check (sex in ('M ', 'F') create table players (playerno int not null, birth_date date, sex char (1) not null, check (sex in ('M', 'F ')) joined smallint not null, check (year (birth_date) <joined), check (joined <1880),) create table players (playerno int not null, birth_date date, sex char (1) not null, check (sex in (select sex from wholetab ))

 


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.