Professional Documents
Culture Documents
To Create A Table With Constraints in Oracle
To Create A Table With Constraints in Oracle
CREATE TABLE table_name ( column1 data_type constraints, column2 data_type constraints, ...
columnN data_type constraints );
In this query, you need to replace table_name with the desired name for your table and column1,
column2, ..., columnN with the actual column names you want to create. data_type should be replaced
with the appropriate data type for each column.
Now, let's look at some common constraints that you can include:
sqlCopy code
2. Unique Constraint:
sqlCopy code
CREATE TABLE table_name1 ( column1 data_type PRIMARY KEY, ... ); CREATE TABLE table_name2 (
column1 data_type, column2 data_type, ... CONSTRAINT fk_name FOREIGN KEY (column1) REFERENCES
table_name1 (column1) );
In this example, table_name1 is the referenced table, and table_name2 is the table containing the
foreign key.
These are just a few examples of constraints you can use. There are more options available, such as
check constraints, unique key constraints, etc. You can mix and match these constraints based on your
requirements.
Remember to replace data_type with the appropriate data type for each column and provide
meaningful names for the constraints (PRIMARY KEY, UNIQUE, NOT NULL, fk_name, etc.).