- Learning PostgreSQL 10(Second Edition)
- Salahaldin Juba Andrey Volkov
- 290字
- 2021-07-02 22:42:03
Domain integrity constraint
The domain integrity constraint ensures data validity. The first step in defining the domain integrity constraint is to determine the appropriate data type. The domain data types could be integer, real, boolean, character, text, inet, and so on. For example, the data type of first name and email address is text. After specifying the data type, check constraints, such as the mail address pattern, need to be defined.
- Check constraint: A check constraint can be applied to a single attribute or a combination of many attributes in a tuple. Let's assume that the customer_service schema is defined as customer_id, service_id, start_date, end_date, order_date. For this relation, we can have a check constraint to make sure that start_date and end_date are entered correctly by applying the following check start_date<end_date.
- Default constraint: The attribute can have a default value. The default value could be a fixed value such as the default hourly wage of the employees, for example, $10. It may also have a dynamic value based on a function such as random, current time, and date. For example, in the customer_service relation, order_date can have a default value, which is the current date.
- Unique constraint: A unique constraint guarantees that the attribute has a distinct value in each tuple. It allows null values. For example, let's assume that we have a relation player defined as player (player_id, player_nickname). The player uses his ID to play with others; he can also pick up a nickname which is also unique to identify himself.
- Not null constraint: By default, the attribute value can be null. The not null constraint restricts an attribute from having a null value. For example, each person in the birth registry record should have a name.
推薦閱讀
- PPT,要你好看
- Cinema 4D R13 Cookbook
- ETL with Azure Cookbook
- 計算機(jī)應(yīng)用復(fù)習(xí)與練習(xí)
- 程序設(shè)計語言與編譯
- 圖形圖像處理(Photoshop)
- 數(shù)據(jù)庫原理與應(yīng)用技術(shù)學(xué)習(xí)指導(dǎo)
- 自動化控制工程設(shè)計
- 智能工業(yè)報警系統(tǒng)
- Spark大數(shù)據(jù)技術(shù)與應(yīng)用
- 高維聚類知識發(fā)現(xiàn)關(guān)鍵技術(shù)研究及應(yīng)用
- Machine Learning with Apache Spark Quick Start Guide
- 人工智能云平臺:原理、設(shè)計與應(yīng)用
- Learning iOS 8 for Enterprise
- Mastering SQL Server 2014 Data Mining