当前位置:网站首页>Integrity constraints of SQL Server database
Integrity constraints of SQL Server database
2022-07-26 11:30:00 【Baby paper d】
There are four types of constraints in the database to ensure integrity :
| Domain integrity —— Constraints on Columns | |
| Entity integrity —— Constraints on rows ( Cannot use duplicate lines ) | |
| Citation integrity —— A column value in one table is derived from another table | |
| Custom integrity ( This may be a little esoteric , Not understood ) |
1. Constraint methods to ensure domain integrity : Check constraint 、 Default constraint 、 Non empty constraint
Check constraints, that is Check constraint , Another point is to control conditions , But the writing of conditions cannot be so casual , There are also norms , As for this specification ,,, At present, I will use : Gender choice :sex = 'men' or sex = 'women', Or is it sex IN('men' , 'women'), For mail @ Requirements for symbols :email “%@%”, It means that there must be @ Symbol ,% Indicates that there are any bytes , Judgment of size relationship : for example hours > 0, There is also a judgment of length :length(log) >= 6 ( among sex、email、hours、log Are the names of columns in the table ).
The default constraint is when no value is entered , Display the default value of the setting , The setting position is in the default value or binding of the following column properties .
A non empty constraint is whether a table is allowed to be empty when it is designed .
2. Constraint method to ensure entity integrity : Unique constraint 、 Primary key constraint 、 identifier
Both the unique constraint and the primary key constraint are to ensure that the values in a column cannot be repeated , Primary key constraints can set multiple columns as primary keys , This increases the possibility , That is, as long as the columns of the primary key are not exactly the same .
identifier , The first must be int type , And the identifier cannot be edited , It is automatically generated . If a column is deleted , Its identification column cannot be automatically updated .
3. Constraint methods to ensure referential integrity : Foreign key constraints
It's a watch ( From the table ) One or more columns in ( From the key ) Is quoted from another table ( Main table ) Of , That is, from this column in the table ( I.e. slave key ) The data in must be existing in the main table ( This also determines why the values in the main table should be entered first when entering data ). The setting method is : Right click the column name -> Relationship -> add to -> Table and column specifications , Then set the primary key table from the key table , And the primary and secondary keys .
Precautions after the establishment of main and foreign keys :
1. When there is no corresponding record in the main table , Cannot add record to slave table
2. You cannot change the value in the main table to isolate the records in the child table
3. When there are records corresponding to the main table in the sub table , The row cannot be deleted from the main table
4. Before deleting the main table , Delete the sub table first
边栏推荐
- 五万美元的年薪是如何花光的
- Understanding of Abstract Programming
- 数据可视化-《白蛇2:青蛇劫起》(2)
- [vscode]如何远程连接服务器
- HCI interface
- win10 1903 笔记本开热点出现蓝屏问题
- An error occurred in the scrapy shell
- Connection between PLC and servo motor
- Want the clouds in the picture to float? Video editing services can be achieved in three steps with one click
- Basic concepts of JVM and memory management model
猜你喜欢
随机推荐
-bash: ./build. Sh: /bin/bash^m: bad interpreter: no that file or directory
3dunity game project actual combat - aircraft war
【转载】多元高斯分布(The Multivariate normal distribution)
easyui03
[vscode] how to connect to the server remotely
配置文件以rc结尾什么意思
Simple use of MySQL database
Pyqt5 rapid development and practice Chapter 1 understanding pyqt5
数据中台建设(二):数据中台简单介绍
Pyqt5 rapid development and practice 3.1 QT designer quick start
Pytest fixture decorator
Shape matching Halcon template
PostgreSQL在Linux和Windows安装和入门基础教程
Basic concepts of JVM and memory management model
Dictionary and int matrix
mother
Logging learning final edition - configured different levels of log printing colors
A new technical director asked me to do an IP territorial function~
[开发工具] IEDA报红
What does it mean that the configuration file ends in RC





![36. [difference between const function and function]](/img/14/0f01fdace2ec17e873522cef4ac735.png)
![[vscode] how to connect to the server remotely](/img/b4/9a80ad995bd589596d8b064215b55a.png)


