- 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.
推薦閱讀
- 工業機器人產品應用實戰
- Learning Microsoft Azure Storage
- 實時流計算系統設計與實現
- Learning Social Media Analytics with R
- Visual C# 2008開發技術詳解
- Python Algorithmic Trading Cookbook
- 視覺檢測技術及智能計算
- Pig Design Patterns
- Visual C++編程全能詞典
- 運動控制器與交流伺服系統的調試和應用
- 樂高機器人—槍械武器庫
- 精通數據科學:從線性回歸到深度學習
- Hands-On Data Warehousing with Azure Data Factory
- The DevOps 2.1 Toolkit:Docker Swarm
- Cortex-M3嵌入式處理器原理與應用