constraint
1. Primary key constraint
For example, create a student table and set the student number as the primary key. After creating the table, view the table structure through SHWO COLUMNS FROM student CREATE TABLE student( id int PRIMARY KEY, stu_name varchar(20) ); 2. Unique constraint
For example, create a teacher table with an auto-increment id field and a unique tea_name field. CREATE TABLE teacher( id int AUTO_INCREMENT PRIMARY KEY, tea_name varchar(20) NOT NULL UNIQUE KEY ); 3. Default Constraints
For example, create a course table with a default class time of 40 minutes. CREATE TABLE course( id int AUTO_INCREMENT PRIMARY KEY, cou_name varchar(20) NOT NULL UNIQUE KEY, time int DEFAULT 40 ); INSERT INTO course(cou_name) values('Chinese'); 4. Not Null Constraint
For example, when creating the "Persons" table, create not null constraints in the Id column and the name column: create table Persons( id int not NULL, p_name varchar(20) not null, deparment varchar(20), address varchar(20), telNum varchar(20) ) DESC Persons; 5. Foreign key constraints
1. The parent table and child table must use the same storage engine, and temporary tables are prohibited. CREATE TABLE school( id int AUTO_INCREMENT PRIMARY KEY, sname varchar(20) NOT NULL ); CREATE TABLE student2( id int AUTO_INCREMENT PRIMARY KEY, sid int, FOREIGN KEY (sid) REFERENCES school(id) ); Referential Operations on Foreign Key Constraints
CREATE TABLE student3( id int AUTO_INCREMENT PRIMARY KEY, sid int, FOREIGN KEY (sid) REFERENCES school(id) ON DELETE CASCADE );
Summarize The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links You may also be interested in:
|
<<: Several ways to switch between Vue Tab and cache pages
>>: How to use the markdown editor component in Vue3
TOP Observation: The percentage of CPU time occup...
Table of contents 1. System monitoring 2. File Op...
Today I will take you through the history of ext4...
Table of contents 1. Global Guard 1. Global front...
The fixed IP address of the centos-DVD1 version s...
Firewall A firewall is a set of rules. When a pac...
Install fastdfs on Docker Mount directory -v /e/f...
1. In addition to the default port 8080, we try t...
Table of contents Overview 1. Application-level m...
Table of contents 1. Script vim environment 2. Ho...
Table of contents Routing Manager background gett...
I installed IE8 today. When I went to the Microso...
In the world of web development, frameworks are ve...
1. Command Introduction The date command is used ...
Index definition: It is a separate database struc...