开发者社区> 问答> 正文

Why do we use SQL constraints? Which constraints w

Why do we use SQL constraints? Which constraints we can use while creating a database in SQL?

展开
收起
1780169608831412 2021-10-16 14:23:18 403 0
1 条回答
写回答
取消 提交回答
  • 网络规划设计师、敏捷专家、CISP、ITSS服务经理、ACA全科目、ACP4项、ACE、CBP、CDSP、CZTP等。拥有 PRINCE2 Foundation/Practitioner、CCSK、ITIL、ISO27001、PMP等多项国际认证。 专利5+、期刊10+、知识产权师。核心期刊审稿人。

    Constraints are used to set the rules for all records in the table. If any constraints get violated then it can abort the action that caused it.

    Constraints are defined while creating the database itself with the CREATE TABLE statement or even after the table is created once with the ALTER TABLE statement.

    There are 5 major constraints are used in SQL, such as

    NOT NULL: That indicates that the column must have some value and cannot be left NULL.
    UNIQUE: This constraint is used to ensure that each row and column has a unique value and no value is being repeated in any other row or column.
    PRIMARY KEY: This constraint is used in association with NOT NULL and UNIQUE constraints such as on one or the combination of more than one column to identify the particular record with a unique identity.
    FOREIGN KEY: It is used to ensure the referential integrity of data in the table. It matches the value in one table with another using the PRIMARY KEY.
    CHECK: It ensures whether the value in columns fulfills the specified condition.
    
    2021-10-16 15:14:52
    赞同 1 展开评论 打赏
问答分类:
SQL
问答地址:
问答排行榜
最热
最新

相关电子书

更多
SQL Server在电子商务中的应用与实践 立即下载
GeoMesa on Spark SQL 立即下载
原生SQL on Hadoop引擎- Apache HAWQ 2.x最新技术解密malili 立即下载