Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
11 views

Dbms Assignment

Uploaded by

gargvanshika001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Dbms Assignment

Uploaded by

gargvanshika001
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 31

ASSIGNMENT-1

QUES1. Create an ER diagram for college-


 Student(unique student number(USN),address,phone,gender)
 SEMSEC(SSID,SEM,SEC)
 Class(USN,SSID)
 Subject(sub_code,title,sem,credits)
 IA marks(USN,subcode,SSID,test1,test2,test3,final IA)

PHONE
GENDER SEM
SSID
USN

SEC

STUDENT CLASS SEMSEC


ADDRESS

CLASS_MARKS
SECURES

CREDITS SEM

SCORED_IN

IAMARKS SUBJECT

TEST 1
TEST3
TITLE
SUBCODE

TEST2
FINAL IA
ASSIGNMENT-2
Q1. Create table students . Write queries to execute following DDL commands :
1. CREATE: Create the structure of a table with at least five columns
2. ALTER: Change the size of a particular column.
3. Add a new column to the existing table.
4. Remove a column from the table.
5. DROP: Destroy the table along with its data.
Answer:-
1. CREATE: Create the structure of a table with at least five columns

2. ALTER: Change the size of a particular column.

3. Add a new column to the existing table.


4. Remove a column from the table.

5. Destroy the table along with its data.

Q2. Create a table named "Employees" with the provided schema.

Perform the following DDL operations on the "Employees" table:


1. Alter the size of the "salary" column to accommodate larger salary
2. Add a new column for storing email addresses.
3. Modify the size of the "department" column.
4. Remove the "hire_date" column.
5. Drop the "Employees" table.
Answer:-
Create a table named "Employees" with the provided schema

1. Alter the size of the "salary" column to accommodate larger salary

2. Add a new column for storing email addresses.

3. Modify the size of the "department" column


4. Remove the "hire_date" column.

5. Drop the "Employees" table.

Q3. Consider the following tables in a database:


Write SQL queries to perform the following DML operations:
1. INSERT: Insert five records into each table with sample data.
2. UPDATE: Modify data in single and multiple columns in a table.
3. DELETE: Delete selective and all records from a table.
Answer:-

1. INSERT: Insert five records into each table with sample data.
2. Modify data in single and multiple columns in a table.

A) Modify the grade of the student with ID 3 to 'A'.

B) Modify the age and grade of the student with ID 4.


3. Delete selective and all records from a table

A) Delete the record of the student with ID 2.

B) Delete all records from the Students table.


Q4. Create Employee Table and orders table and enter the following queries:-

1. Modify the salary of employee with ID 3 to 54000.00.


2. Modify the department and hire date of employee with ID 5.
3. Delete the record of the order with ID 102.
4. Delete all records from the Orders table.

Answer:-
1. Modify the salary of employee with ID 3 to 54000.00.

2. Modify the department and hire date of employee with ID 5.

3. Delete the record of the order with ID 102.

4. Delete all records from the Orders table.


Q5. Create table Department with fields:
Dno(Primary Key), Dname(Unique) , Dlocation

Q2. Create table Employee with fields:


Eno(Primary Key), Ename(Not Null), Salary, Designation, Dno(Foreign Key)

Q3. Insert 5 records in both tables


Department
Dno Dname Dlocation
10 Sales Noida
20 Finance Gurgaon
30 HR Delhi
40 Marketing Delhi
50 IT Gurgaon
Employee
Eno Ename Salary Designation Dno
101 Akash 40000 Manager 30
102 Neha 30000 Executive 50
103 Kunal 25000 Executive 10
104 Saksham 60000 Manager 50
105 Dheeraj 50000 Team Leader 20
Q4. Display the details of the employee who draws maximum salary.

Q5. Display the details of those employees whose salary is greater than the average
salary in the organization.

Q6. Display the details of the employee whose Department location is Noida.
Q7. Display the Department Locations to which employees belong.

Q8. Increase the Salary of Employees by 1000Rs whose Designation is Manager.


Q9. Change the column name Designation to Job.

Q10. Delete the column Dlocation.


Q6. Write queries to execute following DML commands :
1. SELECT: Retrieve the entire contents of the table.
2. Retrieve the selective contents (based on provided conditions) from a table.
Retrieve contents from a table based on various operators i.e. string
operators, logical operators and conditional operators, Boolean operators.
3. Sort the data in ascending and descending order in a table on the basis of
one column or more than one column.
String Operators:
Question 1: Write an SQL query to retrieve all products whose names start
with the letter 'S'.

Question 2: How would you extract the first 3 characters from the product
names in the "Electronics" category?
Question 3: Find all products where the product name contains the word

'smartphone'.
Question 4: Retrieve products with names ending in 's' and having a price
greater than $500.

Question 5: How can you concatenate the product name and category,
separated by a hyphen, for all products?
Logical Operators:
Question 1: Retrieve products with a price greater than $100 and a stock
quantity less than 50.

Question 2: Find products with a price less than $50 or a stock quantity greater
than 100.

Question 3: Retrieve products in the 'Electronics' category and have a price


greater than $200.
Question 4: Find products with a price less than $50 and either belong to the
'Clothing' category or have a stock quantity greater than 50.

Question 5: Retrieve products with a price between $50 and $100 and not in the
'Electronics' category.

Conditional Operator:
Question 1: Retrieve products with a price greater than $100 and label them as
'Expensive'.

Question 2: Retrieve products with a stock quantity less than 50 and label them
as 'Low Stock'.

Question 3: Retrieve products with a price between $50 and $100 and categorize
them as 'Standard'.
Question 4: Retrieve products in the 'Electronics' category with a stock
quantity greater than 100 and label them as 'High Demand'.

Question 5: Retrieve products with a price less than $50 and categorize them as
'Budget'.
Sorting
Question 1: Write an SQL query to retrieve all products from the Products
table sorted by their price in ascending order

.
Question 2: How would you retrieve products from the Clothing category
sorted alphabetically by their product names in descending order?

Question 3: Find all products from the Electronics category sorted by their
stock quantity in descending order.
Question 4: Retrieve products with a price greater than $50 sorted by their
price in descending order and then by their category in ascending order

Question 5: Write an SQL query to retrieve products sorted by their stock


quantity in descending order, and for products with the same stock quantity,
sort them by their price in ascending order.
Q7. Create table using following integrity constraints:
 Primary Key
 Unique Key
 Not Null
 Check
 Default
 Foreign Key
6.1 Create a table named "Employees" with the following columns and integrity
constraints:
 employee_id (Primary Key): Unique identifier for each employee.
 employee_name (Not Null): Name of the employee, cannot be null.
 department (Not Null): Department in which the employee works, cannot be
null.
 salary (Check): Salary of the employee, must be greater than or equal to 0.
 hire_date (Default): Date on which the employee was hired, defaults to the
current date.
 manager_id (Foreign Key): References the employee_id column in the same
table, representing the manager of the employee.
Insert the records to test the integrity constraints.
INSERT INTO Employees (employee_id, employee_name, department, salary,
hire_date, manager_id) VALUES
(1, 'John Doe', 'IT', 60000.00, '2023-01-15', NULL),
(2, 'Jane Smith', 'HR', 65000.00, '2022-05-20', NULL),
(3, 'Alice Johnson', 'Marketing', 55000.00, '2023-03-10', 2),
(4, 'Bob Williams', 'Finance', 70000.00, '2021-11-28', 2),
(5, 'Emily Brown', 'Sales', 58000.00, '2022-09-05', 4);
6.2 Create a table named "Students" with the following columns and integrity
constraints:
 student_id (Primary Key): Unique identifier for each student.
 student_name (Not Null): Name of the student, cannot be null.
 course (Not Null): Course in which the student is enrolled, cannot be null.
 grade (Check): Grade of the student, must be between 'A' and 'F'.
 admission_date (Default): Date on which the student was admitted, defaults
to the current date.
 advisor_id (Foreign Key): References the student_id column in the same table,
representing the advisor of the student.
Insert the records to test the integrity constraints.
INSERT INTO Students (student_id, student_name, course, grade, advisor_id)
VALUES
(1, 'Alice Johnson', 'Computer Science', 'A', NULL),
(2, 'Bob Williams', 'Mathematics', 'B', NULL),
(3, 'Charlie Brown', 'Physics', 'C', 1),
(4, 'Diana Smith', 'Chemistry', 'B', 1),
(5, 'Emily Davis', 'Biology', 'A', 2);

You might also like