![]() ![]() If you want to add a unique constraint to an existing table, you use the ALTER TABLE statement: ALTER TABLE table_nameĪDD CONSTRAINT unique_constraint_name UNIQUE(column_name1, column_nam2) This specifies that the combination of values in the column_name1 and column_name2 is unique across the whole table, though any one of these columns need not be unique. ![]() To define a unique constraint for a group of columns, you use the out-of-line constraint syntax: CREATE TABLE table_name (ĬONSTRAINT unique_constraint_name UNIQUE(column_name1, column_name2) Or with out-of-line constraint syntax: CREATE TABLE table_name (ĬONSTRAINT unique_constraint_name UNIQUE(column_name) It’s possible to assign a unique constraint a name by using the CONSTRAINT clause followed by the constraint name: CREATE TABLE table_name (Ĭolumn_name data_type CONSTRAINT unique_constraint_name UNIQUE You can also use the out-of-line constraint syntax to define a unique constraint: CREATE TABLE table_name ( This unique constraint specifies that the values in the column_name is unique across the whole table. Typically, you apply the unique constraints to columns when you create the table using the inline constraint syntax as follows: CREATE TABLE table_name (Ĭode language: SQL (Structured Query Language) ( sql ) Oracle unique constraint syntaxĪ unique constraint is an integrity constraint that ensures the data stored in a column, or a group of columns, is unique among the rows in a table. Summary: in this tutorial, you will learn how to use the Oracle unique constraint to ensure the data contained in a column, or a group of columns, is unique among the rows in the table. ![]()
0 Comments
Leave a Reply. |