0% found this document useful (1 vote)
62 views

SQL Queries - Joins

The document describes creating and populating tables in a database. It creates three tables: Student, Course, and StudentCourse. The Student table stores student details, Course stores course details, and StudentCourse stores the grades for students in courses. Data is inserted into all three tables to populate them with sample records. Several queries are listed at the end to retrieve data from the tables.

Uploaded by

Vishy Anand
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
62 views

SQL Queries - Joins

The document describes creating and populating tables in a database. It creates three tables: Student, Course, and StudentCourse. The Student table stores student details, Course stores course details, and StudentCourse stores the grades for students in courses. Data is inserted into all three tables to populate them with sample records. Several queries are listed at the end to retrieve data from the tables.

Uploaded by

Vishy Anand
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Table creation and data insertion:

i)

create table Student_Anand_12665(


sid int NOT NULL PRIMARY KEY,
sname varchar(10),
sbranch char(5),
sage int CONSTRAINT sage_ck CHECK (sage<=25)
);
create table Course_Anand_12665(
cid int NOT NULL PRIMARY KEY,
cname char(4) UNIQUE,
credits int
);
create table StudentCourse_Anand_12665(
sno int NOT NULL,
cno int NOT NULL,
grade char(1),
CONSTRAINT StudentCourse_PK PRIMARY KEY (sno, cno),
CONSTRAINT StudentCourse_FK1 FOREIGN KEY (sno) REFERENCES
Student_Anand_12665(sid),
CONSTRAINT StudentCourse_FK2 FOREIGN KEY (cno) REFERENCES
Course_Anand_12665(cid)
);
ii)

Insert All
into Student_Anand_12665(sid, sname, sbranch, sage) values
('101','Kiran','CSE','19')
into Student_Anand_12665(sid, sname, sbranch, sage) values
('104','Mohan','EEE','20')
into Student_Anand_12665(sid, sname, sbranch, sage) values
('105','John','CSE','19')
into Student_Anand_12665(sid, sname, sbranch, sage) values
('107','Sara','Mech','21')
into Student_Anand_12665(sid, sname, sbranch, sage) values
('109','James','EEE','20')
into Student_Anand_12665(sid, sname, sbranch, sage) values
('110','Ramesh','CSE','21')
into Student_Anand_12665(sid, sname, sbranch, sage) values
('112','Gopal','EEE','20')
select * from dual;

Insert All
into Course_Anand_12665(cid, cname, credits) values ('10','OS','3')
into Course_Anand_12665(cid, cname, credits) values ('20','DBMS','4')
into Course_Anand_12665(cid, cname, credits) values ('30','MATH','4')
into Course_Anand_12665(cid, cname, credits) values ('40','ARCH','3')
select * from dual;

Insert All
into StudentCourse_Anand_12665(sno, cno, grade) values ('101','20','A')
into StudentCourse_Anand_12665(sno, cno, grade) values ('101','30','A')
into StudentCourse_Anand_12665(sno, cno, grade) values ('105','10','B')
into StudentCourse_Anand_12665(sno, cno, grade) values ('105','20','C')
into StudentCourse_Anand_12665(sno, cno, grade) values ('105','40','A')
into StudentCourse_Anand_12665(sno, cno, grade) values ('107','10','D')
into StudentCourse_Anand_12665(sno, cno, grade) values ('107','40','A')
into StudentCourse_Anand_12665(sno, cno, grade) values ('109','20','B')
into StudentCourse_Anand_12665(sno, cno, grade) values ('109','30','C')
into StudentCourse_Anand_12665(sno, cno, grade) values ('109','40','D')
select * from dual;
iii)

Select * from Student_Anand_12665

Select * from Course_Anand_12665


Select * from StudentCourse_Anand_12665
SQL Queries:

Q1:
Q2.
Q3.
Q6.
Q7.
Q10.
Q9.
Q8.

You might also like