Home >Database >Mysql Tutorial >Data integrity of SQL server database
The data in the database is input from the outside world, and due to various reasons, invalid input or error messages may occur during data input. Ensuring that the input data complies with regulations has become the primary concern of database systems, especially multi-user relational database systems. Data integrity is therefore brought up. This chapter will describe the concept of data integrity and how to implement it in SQL Server.
Data integrity (Data Integrity) refers to the accuracy (Accuracy) and reliability (Reliability) of data. It is proposed to prevent the existence of data that does not comply with semantic regulations in the database and to prevent invalid operations or error messages caused by the input and output of incorrect information. Data integrity is divided into four categories: Entity Integrity, Domain Integrity, Referential Integrity, and User-defined Integrity.
The database uses a variety of methods to ensure data integrity, including foreign keys, constraints, rules and triggers. The system handles the relationship between these four very well, and uses different methods according to different specific situations, and they are used interchangeably to complement each other's shortcomings.
Entity integrity constraints: constraints on a column (primary key (PRIMARY KEY) constraints)
Entity (row) integrity: All rows in the table are required to be unique, such as primary key values.
-------------------------------------------------- -----------
Domain integrity constraints: Constraints on a row (default constraint , check (check) constraint, non not null constraint).
Domain (column) integrity: Specify a set of valid values for the column and decide whether to allow null values. Data integrity can also be enforced by limiting the data type, format, and range of possible values in a column.
-------------------------------------------------- -----------
Referential integrity constraints: Foreign key constraints related to the primary key
Referential integrity: Ensure that the primary key and Relationships with external keywords.
-------------------------------------------------- -----------
User-defined constraints: In addition to implicit constraints, designers of relational databases can also set other specific constraints for the database. Such constraints are called " User-defined constraints”
The above is the detailed content of Data integrity of SQL server database. For more information, please follow other related articles on the PHP Chinese website!