Domain in Oracle
Domain in Oracle
TAXILA
Submitted By:
Wajeeha Islam
22-SE-18
(OMEGA)
Submitted To:
Ma’am Rabia
Creating and managing databases can be a complex task, especially when dealing with
extensive data types and constraints. The SQL 'DOMAIN' statement acts as a solution to this
concern, providing a way to define a field with specific data type and constraint, which can be
reused throughout the database. This tutorial aims to provide a comprehensive understanding
of the SQL 'DOMAIN' statement, its syntax, usage, and benefits.
In SQL, a DOMAIN is a named data type with a specified size, precision, and constraints. It
allows you to create a custom data type that can be used across multiple tables, ensuring data
integrity and consistency. It's like creating a template for a particular type of column.
Creating a DOMAIN
[DEFAULT expression]
[CHECK (condition)];
Here, 'domain_name' is the name of the domain, 'data_type' is the type of data the domain will
hold, 'DEFAULT expression' is an optional default value, and 'CHECK (condition)' is an
optional constraint that the data must meet.
DEFAULT 0
This statement creates a new DOMAIN called 'Age' that holds INTEGER values. The default
value is 0, and the CHECK constraint ensures that the age is between 0 and 120.
FirstName VARCHAR(50),
LastName VARCHAR(50),
Age INT CHECK (Age >= 18),
);
In this example, EmployeeID is an integer, FirstName and LastName are variable character
strings, Age is an integer with a CHECK constraint ensuring it's 18 or older, and Salary is a
decimal with a CHECK constraint ensuring it's non-negative. These constraints help define the
domain for each column, specifying the valid range or conditions for the data.
FirstName VARCHAR(50),
LastName VARCHAR(50),
);
6. Viewing Table:
User-defined:
1. Create Object Type:
Output:
Conclusion
Understanding the SQL 'DOMAIN' statement and its usage is critical for any software
developer dealing with databases. It not only promotes data consistency and integrity but also
enhances efficiency.