- Learning PostgreSQL 11
- Salahaldin Juba Andrey Volkov
- 302字
- 2021-07-02 13:11:38
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 an integer, real, boolean, character, text, inet, and so on. For example, the data type of the 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, and 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 is less than 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 a 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 prevents an attribute from having a null value. For example, each person in the birth registry record should have a name.
推薦閱讀
- Java語(yǔ)言程序設(shè)計(jì)
- 大話PLC(輕松動(dòng)漫版)
- Instant Testing with CasperJS
- Monkey Game Development:Beginner's Guide
- BeagleBone Media Center
- Java程序設(shè)計(jì)與計(jì)算思維
- Linux:Embedded Development
- SQL Server與JSP動(dòng)態(tài)網(wǎng)站開(kāi)發(fā)
- Learning R for Geospatial Analysis
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)教程(Windows 7+Office 2010)
- 零基礎(chǔ)學(xué)Python編程(少兒趣味版)
- Windows Phone 8 Game Development
- Python Digital Forensics Cookbook
- Building Business Websites with Squarespace 7(Second Edition)
- ASP.NET Core and Angular 2