Logo 
Search:

Oracle Articles

Submit Article
Home » Articles » Oracle » Data Definition LangRSS Feeds

Example to create table, primary key and foreign key in student, course and SC tables

Posted By: Luigi Fischer     Category: Oracle     Views: 6158

This article provides an example to create table, primary key and foreign key in student, course and SC tables.

Code for Example to create table, primary key and foreign key in student, course and SC tables in Oracle

createtable student
(
rollno varchar2(4) primarykeyconstraint chk_rollno check(rollno like'r%'),
name varchar2(30) notnull,
class varchar2(10),
birthdate date
);


createtable course
(
courseno varchar2(4) primarykeyconstraint chk_courseno check(courseno like'c%'),
coursename varchar2(50),
max_marks number(3) constraint chk_max_marks check(max_marks>0),
pass_marks number(3),
constraint chk_pass_marks check(pass_marks>0 and pass_marks<max_marks)
);


createtable sc
(
rollno varchar2(4),
courseno varchar2(4),
marks number(3) constraint chk_marks check(marks>0),
primarykey(rollno,courseno),
foreignkey(rollno) references student(rollno),
foreignkey(courseno) references course(courseno)
);
  
Share: 



Luigi Fischer
Luigi Fischer author of Example to create table, primary key and foreign key in student, course and SC tables is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!