0% found this document useful (0 votes)
11 views8 pages

Lab 44

The document outlines various SQL tasks related to a database management system, including queries to retrieve course information based on specific criteria and instructions for creating and manipulating tables. It includes tasks such as selecting courses with certain characteristics, creating a 'Person' table, inserting records, and managing foreign key constraints. Each task is accompanied by the corresponding SQL solution for implementation.

Uploaded by

code dv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views8 pages

Lab 44

The document outlines various SQL tasks related to a database management system, including queries to retrieve course information based on specific criteria and instructions for creating and manipulating tables. It includes tasks such as selecting courses with certain characteristics, creating a 'Person' table, inserting records, and managing foreign key constraints. Each task is accompanied by the corresponding SQL solution for implementation.

Uploaded by

code dv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Dr. B.R.

Ambedkar National Institute of


Technology, Jalandhar

Lab 4
DBMS

Name - Divyanshu Varshney


Class - CSE 4A G2
Roll No - 23103048
Submitted to- Dr Shefali Arora Chouhan
Task 1: Display the information about any course which has a description
beginning with the string “FOR THE” .
Solution:-
select * from Course
where CDESCP like 'FOR THE%'

Task 2: Display all CNAME values which end with the letters “CISM”.
Solution:-
select * from Course

where CNAME like '%CISM'

Task 3: What are the names of the courses which have the letters “TA”
appearing anywhere in the name?
Solution:-
select * from Course

where CNAME like '%TA%' ;


Task 4: Display the course number and description of any course with a
period, hyphen, or exclamation mark anywhere in its description.
Solution:-
SELECT CNo, CDESCP

FROM Course

WHERE CDESCP LIKE '%.%'

OR CDESCP LIKE '%-%'

OR CDESCP LIKE '%!%' ;

Task 5:- Display the department identifier of any course where the
department identifier ends with “IL”. Do not display duplicate values.
Solution:-
SELECT distinct CDEPT

FROM Course

WHERE CDEPT LIKE '%IL' ;


Task 6:- Display the course name and department identifier of any course
which has the letter “H” present in the second position of its department
identifier and is exactly four characters long .
Solution:-
SELECT CNAME , CDEPT

FROM Course

WHERE CDEPT LIKE '_H__' ;

Task 7:- Display the names of courses which have a vowel as the second
letter of their name.
Solution:-
SELECT CNAME

FROM Course
WHERE CNAME LIKE '_A%'

OR CNAME LIKE '_E%'

OR CNAME LIKE '_I%'

OR CNAME LIKE '_O%'

OR CNAME LIKE '_U%' ;


Task 8:- Display the name and description of any course where the
description has “THE” in the fifth, sixth, and seventh positions, and “A” in
the tenth position.
Solution:-
SELECT CNAME , CDESCP

FROM Course

WHERE CDESCP LIKE '____THE__A%'

Task 9:- Display the names of all courses which do not have a vowel as the
second letter of their name.
Solution:-
SELECT CNAME

FROM Course

WHERE CNAME NOT LIKE '_A%'


AND CNAME NOT LIKE '_E%'

AND CNAME NOT LIKE '_I%'

AND CNAME NOT LIKE '_O%'

AND CNAME NOT LIKE '_U%' ;


Task 10:- Display the course name and description of any course which
does not end with an “E” or an “S”.
Solution:-
SELECT CNAME,CDESCP

FROM Course

WHERE CNAME OR CDESCP NOT LIKE '%E'

AND CNAME OR CDESCP NOT LIKE '%S'

Task 11:- Create a table Person with PersonID as the primary key.
Solution:-
CREATE TABLE Person (

PersonID INT PRIMARY KEY,

LastName VARCHAR(50),

FirstName VARCHAR(50),

Age INT
);
Task 12:- Create a FOREIGN KEY constraint on the "PersonID" column when
the "Orders" table is already created.
Solution:-
ALTER TABLE Orders

ADD CONSTRAINT PersonID FOREIGN KEY (PersonID)


REFERENCES Person(PersonID);

Task 13:- Insert at least 5 records into the Person table and 3 records into
the Orders table.
Solution:-
INSERT INTO Person (PersonID, LastName, FirstName, Age)

VALUES

(1, 'Sharma', 'Preet', 30),

(2, 'Kumar', 'Rishabh', 25),

(3, 'Aggarwal', 'Lakshay', 35),


(4, 'Samour', 'Devang', 40),

(5, 'Khandelwal', 'Vedansh', 28);

INSERT INTO Orders (OrderID, OrderNumber, PersonID)

VALUES

(1, 5201, 1),

(2, 5202, 2),

(3, 5203, 3);


Task 14:- Drop the Foreign Key from the Orders table.
Solution:-
ALTER TABLE Orders

DROP CONSTRAINT PersonId ;

You might also like