什么是数据库约束? [英] What are database constraints?

查看:170
本文介绍了什么是数据库约束?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是数据库约束的清晰定义?为什么约束对数据库很重要?约束是什么类型?

What is a clear definition of database constraint? Why are constraints important for a database? What are the types of constraints?

推荐答案

约束是数据库模式定义的一部分。

Constraints are part of a database schema definition.

约束通常与表关联,并使用 CREATE CONSTRAINT CREATE ASSERTION SQL语句。

A constraint is usually associated with a table and is created with a CREATE CONSTRAINT or CREATE ASSERTION SQL statement.

它们定义数据库中的数据必须遵守的某些属性。它们可以应用于列,整个表,多个表或整个模式。一个可靠的数据库系统可以确保约束在所有时间都有效(除非可能在一个事务内,所谓的延迟约束)。

They define certain properties that data in a database must comply with. They can apply to a column, a whole table, more than one table or an entire schema. A reliable database system ensures that constraints hold at all times (except possibly inside a transaction, for so called deferred constraints).

常见的约束有:


  • not null - 列中的每个值不得为 NULL

  • 唯一 - 指定列中的值对于表中的每一行都必须是唯一的

  • 主键 - 指定列中的值对于表中的每一行必须是唯一的,而不是 NULL ;通常数据库中的每个表都应该有一个主键 - 用于标识单个记录

  • 外键 - 指定列中的值必须引用另一个表中的现有记录(通过主键或其他唯一约束

  • strong> - 指定一个表达式,必须求值为true才能满足约束

  • not null - each value in a column must not be NULL
  • unique - value(s) in specified column(s) must be unique for each row in a table
  • primary key - value(s) in specified column(s) must be unique for each row in a table and not be NULL; normally each table in a database should have a primary key - it is used to identify individual records
  • foreign key - value(s) in specified column(s) must reference an existing record in another table (via it's primary key or some other unique constraint)
  • check - an expression is specified, which must evaluate to true for constraint to be satisfied

这篇关于什么是数据库约束?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆