Вы находитесь на странице: 1из 6

DATABASE MANAGEMENT SYSTEM

PRACTICAL LAB ASSIGNMENT 4 (Based on Different integrity constraints)

1. Create the following tables


STUDENT and RESULT with the following structure:
STUDENT RESULT

Name Type and constraint Description

ROLLNO INT Primary key Roll no of a student

SNAME VARCHAR(20) NOT Employee name


NULL

SHIFT CHAR(1) Should be Morning/Evening Shift


only either M or E

MOBILE NUMERIC(4) default Mobile no


value is 4444

FEES INT Should be College fee


greater than =3000
& less than= 5000

Name Type and Description


constraint
ROLLNO INT Foreign Roll no of a
key references student
STUDENT
MATHS NUMERIC(2) MATHS MARKS
POM NUMERIC(2) POM
DE NUMERIC(2) DE
DS NUMERIC(2) DS
DBMS NUMERIC(2) DBMS
2. Insert the following records into STUDENT Table. Check the record for the last
3 entries, find out the errors & then insert the appropriate data.

ROLLNO SNAME SHIFT MOBILE FEE

1 VINAY M 7902 4000

2 RIMA E 7698 3050

3 MINI E 7698 4500

2 AVI M 2345 4200

5 YUG Y 3456 4500

6 HARI M 5432 2000

3. Insert the following records into RESULT Table. Find error for the last record
entry.

ROLLNO MATHS POM DE DS DBMS

1 56 65 53 55 59

2 72 69 74 77 76

7 83 78 86 88 55
4. Perform the following queries :

i) Describe the structure of the table STUDENT and RESULT.

Student:

create database ab;


use ab;
create table STUDENT(
RollNo INT primary key,
S_NAME varchar(20) not null,
SHIFT char(1) check(SHIFT IN('M','E')),
MOBILE numeric(4) DEFAULT 4444,
FEE int check (FEE>=3000 and FEE<=5000)
);

INSERT INTO STUDENT VALUES(1,'VINAY','M',7902,4000);


INSERT INTO STUDENT VALUES(2,'RIMA','E',7698,3050);
INSERT INTO STUDENT VALUES(3,'MINI','E',7698,4500);
INSERT INTO STUDENT VALUES(2,'AVI','M',2345,4200);
INSERT INTO STUDENT VALUES(5,'YUG','Y',3456,4500);
INSERT INTO STUDENT VALUES(6,'HARI','M',5432,2000);

SELECT * FROM STUDENT;

Result:

create table RESULT(


RollNO INT,
foreign key(RollNo) references STUDENT (RollNo),
MATHS numeric(2),
POM numeric(2),
DE numeric(2),
DS numeric(2),
DBMS numeric(2)
);

INSERT INTO RESULT VALUES(1,56,65,53,55,59);


INSERT INTO RESULT VALUES(2,72,69,74,77,76);
INSERT INTO RESULT VALUES(7,83,78,86,88,55);

SELECT * FROM RESULT;

ii) Select all the records from STUDENT.

SELECT * FROM STUDENT;

iii) Select all the records from RESULT.

SELECT * FROM RESULT;

iv) Update shift and fee of RIMA to M and 4000.

UPDATE STUDENT SET SHIFT='M', FEE=4000 WHERE S_NAME='RIMA';

SELECT * FROM STUDENT;


v) Add one more column/field named ADDRESS with varchar(20) to STUDENT.

ALTER TABLE STUDENT ADD ADDRESS VARCHAR(20);

SELECT * FROM STUDENT;

vi) Insert one more appropriate record to STUDENT.

INSERT INTO STUDENT VALUES(7,'rohit','M',7956,3400,'rohini');

SELECT * FROM STUDENT;

vii) Add result of student MINI assuming your own data.

INSERT INTO RESULT VALUES(3,76,74,90,84,34);

SELECT * FROM RESULT;

viii) Display the result of all students along with their rollno, name and shift.

SELECT S_NAME,SHIFT,MATHS,POM,DE,DS,DBMS FROM


STUDENT,RESULT WHERE STUDENT.RollNO=RESULT.RollNO;
ix) Remove the result of student RIMA.

DELETE FROM RESULT WHERE RollNO = 2;

SELECT * FROM RESULT;

x) Show those students name in alphabetical order with their result who scored better marks in
DBMS than DS.

xi) List the names of all those students who have lowest marks in DBMS.

xii) Shows the result of VINAY in all the subjects.

SELECT * FROM RESULT WHERE RollNO = 1;

xiii) List the names of all those students whose MATHS mark is above the average of MATHS
marks.

Вам также может понравиться