0% found this document useful (0 votes)
9 views6 pages

DBMS 31 Jan

The document contains SQL queries for creating and managing Employee and Student tables, including inserting, updating, and deleting records. It covers tasks such as altering table structures, selecting specific records based on conditions, and renaming columns and tables. The queries demonstrate various SQL functionalities such as data manipulation and schema modification.

Uploaded by

shurtugal3023
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)
9 views6 pages

DBMS 31 Jan

The document contains SQL queries for creating and managing Employee and Student tables, including inserting, updating, and deleting records. It covers tasks such as altering table structures, selecting specific records based on conditions, and renaming columns and tables. The queries demonstrate various SQL functionalities such as data manipulation and schema modification.

Uploaded by

shurtugal3023
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/ 6

NAME: SOURAV BEHERA

ROLL: 121CS0148

Q1. Write SQL queries to perform following tasks.


1. Create Employee table and insert the values.

QUERY:
CREATE TABLE Employee(
EmpId INT UNIQUE,
_Name VARCHAR(200),
Sex CHAR(1),
Salary INT,
Department VARCHAR(50)
);

INSERT INTO Employee(EmpId, _Name, Sex, Salary, Department)


VALUES(1001, 'Sonali', 'F', 100000, 'HR');
INSERT INTO Employee(EmpId, _Name, Sex, Salary, Department)
VALUES(1002, 'Riya', 'F', 1000000, 'SALES');
INSERT INTO Employee(EmpId, _Name, Sex, Salary, Department)
VALUES(1003, 'Karthik', 'M', 150000, 'OPERATIONS');
INSERT INTO Employee(EmpId, _Name, Sex, Salary, Department)
VALUES(1004, 'David', 'M', 200000, 'SALES');

INSERT INTO Employee(EmpId, _Name, Sex, Salary, Department)


VALUES(1005, 'Sameer', 'M', 300000, 'HR');
INSERT INTO Employee(EmpId, _Name, Sex, Salary, Department)
VALUES(1006, 'Rahul', 'M', 2000000, 'OPERATIONS');
INSERT INTO Employee(EmpId, _Name, Sex, Salary, Department)
VALUES(1007, 'Ravi', 'M', 500000, 'SALES');

2. Add column “AGE” in the employee table.

QUERY:
ALTER TABLE Employee
ADD AGE INT;

3. Insert the age of the employees as 23,25,29,24,30,21,22 respectively.

QUERY:
UPDATE Employee SET AGE = 25 WHERE EmpId = 1002;
UPDATE Employee SET AGE = 29 WHERE EmpId = 1003;
UPDATE Employee SET AGE = 23 WHERE EmpId = 1001;
UPDATE Employee SET AGE = 24 WHERE EmpId = 1004;
UPDATE Employee SET AGE = 30 WHERE EmpId = 1005;
UPDATE Employee SET AGE = 21 WHERE EmpId = 1006;
UPDATE Employee SET AGE = 22 WHERE EmpId = 1007;

4. Modify the datatype of department to varchar(80)


QUERY:
ALTER TABLE Employee
ALTER COLUMN Department VARCHAR(80)

5. Add column “Date of Join” and insert the values as “10-10-2005”, “10- 07-2007”, “10-
10-2006”, “10-01-2005”, “18-10-2015”, “10-10-2015”, “30-04-2022” respectively.

QUERY:
UPDATE Employee SET DateOfJoin = '10-10-2005' WHERE EmpId = 1001;
UPDATE Employee SET DateOfJoin = '07-10-2007' WHERE EmpId = 1002;
UPDATE Employee SET DateOfJoin = '10-10-2006' WHERE EmpId = 1003;
UPDATE Employee SET DateOfJoin = '01-10-2005' WHERE EmpId = 1004;
UPDATE Employee SET DateOfJoin = '10-18-2015' WHERE EmpId = 1005;
UPDATE Employee SET DateOfJoin = '10-10-2015' WHERE EmpId = 1006;
UPDATE Employee SET DateOfJoin = '04-30-2022' WHERE EmpId = 1007;

6. Select the employees working “SALES” department.


QUERY:
SELECT * FROM Employee WHERE Department = 'SALES'

7. Select the employees having salary between 2,00,000 and 10,00,000


QUERY:
SELECT * FROM Employee WHERE 200000 <= Salary AND Salary <= 1000000

8. Display the number of months Ravi worked in company.


QUERY:
SELECT DATEDIFF(MONTH,DateOfJoin, GETDATE())
FROM Employee WHERE _Name = 'Ravi'

9. Update the David’s department to “operations”.

QUERY:
UPDATE Employee SET Department = 'OPERATIONS' WHERE _Name = 'David'

10.Delete the employee with Emp Id as “1004”.

QUERY:
DELETE FROM Employee WHERE EmpId=1004
11.Display employees joined after “10-10-2006”.

QUERY:
SELECT * FROM Employee WHERE DateOfJoin >= '10-10-2006'

12.Delete all records of table using truncate command.

QUERY:
TRUNCATE TABLE Employee;

13.Drop the table employee.

QUERY:
DROP TABLE Employee;
Q2. Write SQL queries to perform following tasks

1. Create Student table and insert the values.

QUERY:
CREATE TABLE Student(
Student_ID VARCHAR(20) UNIQUE,
_Name VARCHAR(200),
Age INT,
Fees INT,
Department VARCHAR(50)
);

INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)


VALUES('CSE1001', 'Avinash', 26, 930000, 'CSE');
INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('ACC1002', 'Tejas', 23, 50000, 'Accounts');
INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('ECE1003', 'Vivek', 30, 900000, 'ECE');
INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('CSE1004', 'Jitendra', 25, 930000, 'CSE');
INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('ACC1005', 'Sweta', 31, 50000, 'Accounts');

INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)


VALUES('ECE1006', 'Sweety', 26, 900000, 'ECE');
INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('ECE1007', 'Ravi', 24, 900000, 'ECE');
INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('ECE1008', 'Rahul', 25, 900000, 'ECE');
INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('ACC1009', 'Kartik', 29, 50000, 'Accounts');
INSERT INTO Student(Student_ID, _Name, Age, Fees, Department)
VALUES('CSE1010', 'Pooja', 28, 930000, 'CSE');

2. Modify the datatype of student_ID to varchar(80).


QUERY:
ALTER TABLE Student
ALTER COLUMN Student_ID VARCHAR(80)

3. Display the records of student whose name starts with R.


QUERY:
SELECT * FROM Student WHERE SUBSTRING(_Name, 1, 1) = 'R'
4. Add column “CGPA” in the student table.
QUERY:
ALTER TABLE Student
ADD CGPA FLOAT

5. Insert the CGPA of the students as 8.5, 9.3, 6.7, 9.95, 5.6, 7.6, 8.2, 8.7, 7.4, 9.2
respectively
QUERY:
UPDATE Student SET CGPA = 8.5 WHERE Student_ID = 'CSE1001';
UPDATE Student SET CGPA = 9.3 WHERE Student_ID = 'ACC1002';
UPDATE Student SET CGPA = 6.7 WHERE Student_ID = 'ECE1003';
UPDATE Student SET CGPA = 9.95 WHERE Student_ID = 'CSE1004';
UPDATE Student SET CGPA = 5.6 WHERE Student_ID = 'ACC1005';

UPDATE Student SET CGPA = 7.6 WHERE Student_ID = 'ECE1006';


UPDATE Student SET CGPA = 8.2 WHERE Student_ID = 'ECE1007';
UPDATE Student SET CGPA = 8.7 WHERE Student_ID = 'ECE1008';
UPDATE Student SET CGPA = 7.4 WHERE Student_ID = 'ACC1009';
UPDATE Student SET CGPA = 9.2 WHERE Student_ID = 'CSE1010';

6. Select the student_ID of all students of “CSE” department.


QUERY:
SELECT Student_ID from Student WHERE SUBSTRING(Student_ID, 1,3) = 'CSE';

7. Select the students having age between 25 and 30 and department as “ECE”.
QUERY:
SELECT * FROM Student
WHERE 25 <= Age AND Age <= 30 AND Department = 'ECE'

8. Rename the “Department” column as “Field of Study


QUERY:
EXEC sp_rename Department, FieldOfStudy;

9. Update the Ravi’s Field of study to “CSE” and modify the fees as “930000”.
QUERY:
UPDATE Student SET Department = 'CSE', Fees = 930000
WHERE _Name = 'Ravi'

10.Delete the record with Student Id as “CSE1010”


QUERY:

DELETE FROM Student WHERE Student_ID = 'CSE1010


11. Display the students of CSE department sorted by their CGPA

12.Rename the table as Student_details

QUERY:
EXEC sp_rename Student, StudentDetails;

13.Drop the table student_details.

QUERY:
DROP TABLE StudentDetails;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy