当前位置:网站首页>SQL statement - DDL
SQL statement - DDL
2022-04-23 02:57:00 【Senior agent of Sarkozy】
Learn from :b standing Luo Hao jackfrued The teacher's online class
| SQL sentence | effect | Examples of use |
|---|---|---|
| create | Create database / surface | create database ` Database name `; / create table ` Table name ` ( Field description ); |
| drop | Delete database / surface | drop database ` Database name `; / drop table ` Table name `; |
| use | Select database | use ` Database name `; |
| alter | Change database / Table information | alter table ` Table name ` add constraint ` Constraint name ` unique (` Field name `); |
PS:
-
Modify the engine of the table / Changing the initial value of the self increasing constraint is in create table ` Table name ` () Added later .
create table ` Table name `( )engine = innodb auto_increment=2 comment ' Example ';
constraint
Primary key constraint
primary key (` Name `),
Compound primary keys are syntactically correct , But it's very difficult to use when developing , At least two fields are required to uniquely identify a record . Generally not used .
If you choose a timetable , There are course number and student number fields , Combined as a composite primary key, records can be uniquely determined . But usually a new elective course will be created id For example, you can uniquely determine the fields of all course selection records as the primary key .
Self increasing constraint 、 Non empty constraint
Just write after the field description
`col_name` int auto_increment not null comment ' Name ',
The following three can be written when creating a table , You can also write later alter table Table name add constraint....
Unique constraint
constraint `uk_col_name` unique (`col_name`),
Similar to primary key constraint , A unique constraint can also set multiple fields , Just write a few more fields in parentheses ( Such as course selection record , A student can't choose courses repeatedly , Student number and course number cannot be repeated )
Check constraint
Checking constraints can help check the validity of data , But relative , There must be a loss of performance .
constraint `ck_col_sex` check (`col_sex`='M' or `col_sex`='F'),
Foreign key constraints
First, add the same format as the primary key of another table to the table that needs to be added with a foreign key ( The name can be different ) Field of .
The performance of foreign keys will also be lost , To check whether the corresponding field in the corresponding table corresponds to . Many companies don't use foreign key constraints , Other methods will be used to determine whether the specific fields of the two tables correspond to .
constraint `fk_col_id` foreign key (` Field names in this table `) references ` Another table name ` (` The primary key name in this table `),
One to many hours , More than one side needs to add foreign key constraints .
版权声明
本文为[Senior agent of Sarkozy]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220647385026.html
边栏推荐
- Airtrack cracking wireless network password (Dictionary running method)
- Huashu "deep learning" and code implementation: 01 Linear Algebra: basic concepts + code implementation basic operations
- Close the computer port
- tf. keras. layers. Conv? D function
- Niuke white moon race 6 [solution]
- OCR recognition PDF file
- Les derniers noeuds K de la liste jz22
- BLDC double closed loop (speed PI + current PI) Simulink simulation model
- Servlet template engine usage example
- MySQL function syntax
猜你喜欢

Guangcheng cloud service can fill in a daily report regularly every day

Shell script learning notes - regular expressions

Kubernetes - Introduction to actual combat

tf. keras. layers. MaxPooling? D function

Actual combat of industrial defect detection project (IV) -- ceramic defect detection based on hrnet

How can enterprises with major hazard installations ensure the completion of the digital construction task of double prevention mechanism by the end of the year

Traversal of l2-006 tree (middle and later order determination binary tree & sequence traversal)

基于ele封装下拉菜单等组件

Linux redis - redis ha sentinel cluster construction details & redis master-slave deployment

解决win7 中powershell挖矿占用CPU100%
随机推荐
Kubernetes study notes
B blocks of the 46th ICPC Asian regional competition (Kunming)
Modify the content of MySQL + PHP drop-down box
Huawei machine test question -- deformation of hj53 Yang Hui triangle
Get together to watch (detailed version) eat a few cents a day
tf. keras. layers. Conv? D function
Encapsulate components such as pull-down menu based on ele
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
ROP Emporium x86_64 7~8题
【Hcip】OSPF常用的6种LSA详解
Chapter V project quality management of information system project manager summary
Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
AC380V drop 5v12v24v200ma, UHV non isolated chip IC scheme
AC & A2C & A3C
Log cutting - build a remote log collection server
If MySQL / SQL server judges that the table or temporary table exists, it will be deleted
Reverse a linked list < difficulty coefficient >
Configuring Apache Web services for servers such as Tianyi cloud
Shell script learning -- practical case
Mosaic Routing: implement / home / news