Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, friends.

How can I add two or more constraints in the same line in CREATE TABLE Statement in ORACLE 10g, I've tried this statement but it's failed:

CREATE TABLE Students(
ID INT PRIMARY KEY,
NAME VARCHAR2(50),
SOCIAL VARCHAR2(10) NOT NULL CHECK (SOCIAL IN ('Single','Married'))
);

but it doesn't work.
Also I can't make a composite key in the table!!!
Posted
Comments
Suvendu Shekhar Giri 6-Nov-15 16:26pm    
This is perfectly fine and should execute.
Can you elaborate a little more about "..but it doesn't work"?
Ma3d Sa3eed 7-Nov-15 13:44pm    
I cannot make a composit key in the table using PRIMARY KEY(column1, column2), it says: cannot insert more than a primary key in the same table.

1 solution

Try:
SQL
CREATE TABLE Students(
    ID INT,
    NAME VARCHAR2(50),
    SOCIAL VARCHAR2(10) NOT NULL CHECK (SOCIAL IN ('Single','Married')),
    CONSTRAINT students_pk PRIMARY KEY (id,name)
    )
;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900