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
I recently used the MySql database when developin...
1. Add the isolation marker: ip netns add fd 2. P...
C++ connects to MySQL for your reference. The spe...
This article describes MySQL multi-table query wi...
Preface: The most commonly used MySQL logical bac...
This article uses the deep learning framework ker...
1. View the renderings Select forward: Select bac...
Q: Whether using Outlook or IE, when you right-cl...
This article introduces how to install MySQL 8.0 ...
Operation effectCode Implementation html <div ...
There are many import methods on the Internet, an...
<br />Not long ago, due to business needs, I...
LocalStorage stores Boolean values Today, when I ...
I have been using the CentOS purchased by Alibaba...
This topic is an internal sharing in the second h...