Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

CONSTRAINTS ???

3 posters

Go down

CONSTRAINTS ??? Empty CONSTRAINTS ???

Post by praveen Fri Mar 19, 2010 12:00 pm

Can someone tell how to use diff Constraints like primary key , unique , foreign key etc ... with some examples......

Thanx in advance....
praveen
praveen

Posts : 7
Points : 13
Join date : 2010-03-03
Age : 36
Location : Haldia

http://www.praveenbob.blogspot.com

Back to top Go down

CONSTRAINTS ??? Empty Re: CONSTRAINTS ???

Post by Christopher Fri Mar 19, 2010 4:29 pm

Few Examples

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);
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

CONSTRAINTS ??? Empty while creating ??

Post by praveen Fri Mar 19, 2010 5:59 pm

Thanx.........

these are applicable only after creating table rite???

how to make some field as a foreign key , while creating a table ?
praveen
praveen

Posts : 7
Points : 13
Join date : 2010-03-03
Age : 36
Location : Haldia

http://www.praveenbob.blogspot.com

Back to top Go down

CONSTRAINTS ??? Empty Re: CONSTRAINTS ???

Post by parwani_ravi Fri Mar 19, 2010 6:14 pm

@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.

parwani_ravi

Posts : 4
Points : 55
Join date : 2010-03-09
Age : 36
Location : Haldia

Back to top Go down

CONSTRAINTS ??? Empty Re: CONSTRAINTS ???

Post by praveen Fri Mar 19, 2010 6:43 pm

@parwani_ravi

Thank u ........
praveen
praveen

Posts : 7
Points : 13
Join date : 2010-03-03
Age : 36
Location : Haldia

http://www.praveenbob.blogspot.com

Back to top Go down

CONSTRAINTS ??? Empty Re: CONSTRAINTS ???

Post by Christopher Fri Mar 19, 2010 6:54 pm

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))
Christopher
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 35

https://unixcpp.forumotion.com

Back to top Go down

CONSTRAINTS ??? Empty Re: CONSTRAINTS ???

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum