CONSTRAINTS ???
3 posters
Unix C++ :: UNIX CPP :: RDBMS & ORACLE
Page 1 of 1
CONSTRAINTS ???
Can someone tell how to use diff Constraints like primary key , unique , foreign key etc ... with some examples......
Thanx in advance....
Thanx in advance....
Re: CONSTRAINTS ???
Few Examples
PRIMARY KEY CONSTRAINT
FOREIGN KEY
UNIQUE KEY
PRIMARY KEY CONSTRAINT
- Code:
ALTER TABLE STUDENT_DETAILS ADD CONSTRAINT <constraint_name> PRIMARY KEY(ROLLNO);
FOREIGN KEY
- Code:
ALTER TABLE STUDENT_MARKS_HISTORY ADD CONSTRAINT <constraint_name> FOREIGN KEY (ROLLNO) REFERENCES STUDENT_DETAILS(ROLLNO);
UNIQUE KEY
- Code:
ALTER TABLE STUDENT_DETAILS ADD CONSTRAINT <constraint_name> UNIQUE(NAME);
while creating ??
Thanx.........
these are applicable only after creating table rite???
how to make some field as a foreign key , while creating a table ?
these are applicable only after creating table rite???
how to make some field as a foreign key , while creating a table ?
Re: CONSTRAINTS ???
@praveen
the column name should be same and use the keyword REFERENCES
eg. let there is table emp(empid,empname)
now to create foreign key in dept table v can use
dept(deptid, empid number references emp)
and the referenced column should be primary key.
the column name should be same and use the keyword REFERENCES
eg. let there is table emp(empid,empname)
now to create foreign key in dept table v can use
dept(deptid, empid number references emp)
and the referenced column should be primary key.
parwani_ravi- Posts : 4
Points : 55
Join date : 2010-03-09
Age : 36
Location : Haldia
Re: CONSTRAINTS ???
its not necessary tat foreign key has to be in the same name.
- Code:
CREATE TABLE
STUDENT_MARK_HISTORY (RNO NUMBER(4)
CONSTRAINT <constraint_name> REFERENCES STUDENT_DETAILS(ROLLNO),
NAME VARCHAR2(20), AGE NUMBER(2))
Unix C++ :: UNIX CPP :: RDBMS & ORACLE
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|