Used in : Postgre sql
CREATE DOMAIN creates a new domain. A domain is essentially a data type with optional constraints (restrictions on the allowed set of values). The user who defines a domain becomes its owner.
Domains are useful for abstracting common constraints on fields into a single location for maintenance. For example, several tables might contain email address columns, all requiring the same CHECK constraint to verify the address syntax. Define a domain rather than setting up each table’s constraint individually.
CREATE DOMAIN CPI_DATA AS REAL CHECK (value >= 0 AND value <= 10);
Now CPI_DATA domain is create so, we can use this domain anywhere in any table of database as below :
CREATE TABLE student( sid char(9) PRIMARY KEY, name varchar(30), cpi CPI_DATA );
Every time cpi_data will check the constraint, when you add data in student table.
Example 1 :
Insert into student values (201501408,Raj,7.5); This will not violate the property of cpi.
Example 2 :
Insert into student values (201501188,Dhaval,12); ERROR. This will violate the property of cpi.
This article is contributed by Dhavalkumar Prajapati. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- SQL | Procedures in PL/SQL
- SQL | Difference between functions and stored procedures in PL/SQL
- Difference between SQL and T-SQL
- SQL | CREATE
- SQL | Create Table Extension
- Performing Database Operations in Java | SQL CREATE, INSERT, UPDATE, DELETE and SELECT
- Create, Alter and Drop schema in MS SQL Server
- Create login in SQL Server
- Create Database in MS SQL Server
- CREATE and DROP INDEX Statement in SQL
- CREATE SCHEMA in SQL Server
- Mitigation of SQL Injection Attack using Prepared Statements (Parameterized Queries)
- SQL | SELECT Query
- SQL | Distinct Clause
- SQL | WHERE Clause
- SQL | AND and OR operators
- SQL | INSERT INTO Statement
- SQL | DELETE Statement
- SQL | UPDATE Statement
Improved By : Umesh Bhat