0% found this document useful (0 votes)
23 views36 pages

Dsa Assigment

Assignment 2

Uploaded by

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

Dsa Assigment

Assignment 2

Uploaded by

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

Assignment 2

Hamdan Amir L1F22BSCS0160

Shawaiz nisar L1F22BSCS0159

Syed Ahsan L1F22BSCS0179

Muhammad Uzair L1F22BSCS0073

CREATE TABLE Employee (

Employee_Number INT PRIMARY KEY,

Employee_Name VARCHAR(15) NOT NULL,

Job VARCHAR(10) NOT NULL,

Salary INT,

Datee DATE

);

CREATE TABLE Department (

Department_No INT PRIMARY KEY,

Department_Name VARCHAR(25),

Location VARCHAR(20)

);
1. List all information of employee table

SELECT * FROM Employee;


2. List all data from Department table

SELECT * FROM Department;


3. List information of both tables ‘Employee’ and ‘Department’.

SELECT * FROM Employee;

SELECT * FROM Department;


4. List the employee_no, employee_name, job of employee from the employee table.

SELECT Employee_Number, Employee_Name, Job

FROM Employee;
5. List the name, salary of the employees

SELECT Employee_Name, Salary

FROM Employee;
6. List name and annual salary of all the employees

SELECT Employee_Name, Salary * 12 AS Annual_Salary

FROM Employee;

7.Write a query to display the Employe_name and yearly salary using alias “Yearly
Salary"

SELECT Employee_Name, Salary * 12 AS Annual_Salary

FROM Employee;

8. Write a query to get unique department_No from Department table

SELECT DISTINCT Department_No

FROM Department;

9. Write a query to get unique employee_Number from Employee table

SELECT DISTINCT Employee_Number

FROM Employee;
10. Write a query to get all employee details from the employee table order by name,

descending

SELECT *

FROM Employee

ORDER BY Employee_Name DESC;


11. Write a query to get the employee_No, Employee_names, salary in ascending order of

salary

SELECT Employee_Number, Employee_Name, Salary

FROM Employee

ORDER BY Salary ASC;


12. Write a query get all Employee_name from employees table in upper case

SELECT UPPER(Employee_Name) AS Employee_Name

FROM Employee;

13. Write a query to get all jobs from employee table in lower case

SELECT LOWER(Job) AS Lowercase_Job

FROM Employee;

14.Write a query to get the Employee_names and Employee_Number (for example 12

SadiaAslam etc.) of all the employees from employees table

SELECT CONCAT(Employee_Number, ' ', Employee_Name) AS Employee_Info

FROM Employee;
15. Write a query to get the first 2 characters of Employee_name from employee table

SELECT LEFT(Employee_Name, 2) AS First_Two_Characters

FROM Employee;

16. Write a query to get the first 3 characters of location from Department table
SELECT LEFT(Location, 3) AS First_Three_Characters

FROM Department;

17. Write a query to calculate 171*214+625

SELECT 171 * 214 + 625 AS Result;

18. Write a query to print the result of (121*22+44) and name the result set as Result

using as keyword

SELECT (121 * 22 + 44) AS Result;


19. Display your name and enrollment and name the column as “ My_Details”

SELECT 'Hamdan' AS Name, 'Spring' AS Enrollment,

CONCAT('Hamdan', ' - ', 'Spring') AS My_Details;

20. Write a SQL statement to create a simple table countries including columns

country_id,country_name and region_id

CREATE TABLE countries (

country_id INT PRIMARY KEY,

country_name VARCHAR(50),

region_id INT

);
21. Write a SQL statement to create a table named Location including columns loc_id,

Loc_title, min_salary, max_salary

CREATE TABLE Location (

loc_id INT PRIMARY KEY,

Loc_title VARCHAR(50),

min_salary DECIMAL(10, 2),

max_salary DECIMAL(10, 2)

);
22. Write a SQL statement to add column in the table countries to country_new_id

ALTER TABLE countries

ADD country_new_id INT;

23. Add column location.

ALTER TABLE countries

ADD location VARCHAR(50);


24. Write a SQL statement to add a column region_id to the table locations

ALTER TABLE Location

ADD region_id INT;

25. Write a SQL statement to add a columns ID in the table locations


ALTER TABLE Location

ADD ID INT;

26. Write a SQL statement to add a column region_id after state_province to the table

locations(No State province Column in location table)

ALTER TABLE Location

ADD region_id INT AFTER state_province;


27. Write a SQL statement to drop the column city from the table locations

ALTER TABLE Location

DROP COLUMN city;

28. Delete Std_current_semester column from table(There is no table that have current semester data)
ALTER TABLE Students

DROP COLUMN Std_current_semester;

29. Drop column region_id

ALTER TABLE Location

DROP COLUMN region_id;


30. Write a SQL statement to drop column ID from table Location

ALTER TABLE Location

DROP COLUMN ID;

31. Write a query to delete all data from table location


DELETE FROM Location;

32. Write a query to delete all data from table Country

Delete from countries;

33. Delete table Country


Drop table countries;

34. Delete table Location

Drop table Location;

35. Write a SQL statement to insert a record with your own value into the table countries
against each columns

INSERT INTO countries (country_id, country_name, region_id)

VALUES (1, 'Your_Country_Name', 123);

36. Write a SQL statement to insert one row into the table countries against the column

country_id and country_name.

INSERT INTO countries (country_id, country_name)

VALUES (2, 'Pakistan');


37. Write a SQL statement to create duplicate of countries table named country_new with

all structure and data

CREATE TABLE country_new LIKE countries;

INSERT INTO country_new SELECT * FROM countries;


38. Write a SQL statement to insert NULL values against region_id column for a row of

countries table.

INSERT INTO countries (country_id, country_name, region_id)

VALUES (3, 'UK', NULL);

39. Write a SQL statement to insert 3 rows by a single insert statement.

INSERT INTO countries (country_id, country_name, region_id)

VALUES

(4, 'London_4', 123),

(5, 'France_5', 456),

(6, 'Germany_6', 789);


40. Write a SQL statement insert rows from country_new table to countries table.

INSERT INTO countries (country_id, country_name, region_id)

SELECT country_id, country_name, region_id

FROM country_new;
41. Write a SQL statement to insert one row in jobs table to ensure that no duplicate value

will be entered in the job_id column

create table jobs(

job_id int primary key,

job_title varchar(20),

min_salary decimal(10,2),

max_salary decimal(10,2)

);

INSERT INTO jobs (job_id, job_title, min_salary, max_salary)

VALUES (1, 'Programmer', 50000, 100000);

2. Write a SQL statement to insert one row in jobs table to ensure that no duplicate value

will be entered in the job_id column

INSERT INTO jobs (job_id, job_title, min_salary, max_salary)

VALUES (2, 'App Developer', 250000, 900000);


43. In this exercise, you will practice updating and deleting records.

Sure! I can assist you with the SQL statements needed to perform those operations.

44. Update your record in the Employees table to include some Notes.

insert into employee(Employee_Number,Employee_Name,job,Salary,Datee)

values(1,'Hamdan Amir','Programmer',250000,'2024-05-16');

UPDATE employee

SET job = 'Software', Salary = 300000

WHERE Employee_Number = 1;
45. Raise the unit price of all products in the Products table by 10% for all products that

are out of stock. This should affect 5 rows

CREATE TABLE Products (

ProductID INT PRIMARY KEY,

ProductName VARCHAR(100),

UnitPrice DECIMAL(10, 2),

UnitsInStock INT

);

INSERT INTO Products (ProductID, ProductName, UnitPrice, UnitsInStock) VALUES

(1, 'Product A', 100.00, 0),

(2, 'Product B', 200.00, 0),

(3, 'Product C', 150.00, 10);

UPDATE Products

SET UnitPrice = UnitPrice * 1.10

WHERE UnitsInStock = 0;
SELECT * FROM Products;

46. Try to delete yourself from the Employees table. Could you?

DELETE FROM employee

WHERE Employee_Number = 1;
47. If you were not allowed to delete yourself from the Employees table, figure out what

other records you have to delete so that you can.

DELETE FROM employee

WHERE Employee_Number = 1;
48. Insert yourself into the Employees table.

insert into employee(Employee_Number,Employee_Name,job,Salary,Datee)

values(1,'Hamdan Amir','Programmer',250000,'2024-05-16');

49. Include the following

fields: LastName, FirstName, Title, TitleOfCourtesy, BirthDate, HireDate, City, Regi

on, PostalCode, Country, HomePhone, ReportsTo

50. Insert an order for yourself in the Orders table.

51. Include the following fields: CustomerID, EmployeeID, OrderDate, RequiredDate

CREATE TABLE Orders (

OrderID INT PRIMARY KEY AUTO_INCREMENT,

CustomerID VARCHAR(50),

EmployeeID INT,

OrderDate DATE,

RequiredDate DATE
);

INSERT INTO Orders (OrderID,CustomerID, EmployeeID, OrderDate, RequiredDate)

VALUES (1,'ABC123', 101, '2024-05-16', '2024-05-20');

52. Insert order details in the Order_Details table.

53. Include the following fields: OrderID, ProductID, UnitPrice, Quantity, Discount

CREATE TABLE order_details (

OrderDetailID INT PRIMARY KEY,

OderID INT,

ProductID INT,

UnitPrice DECIMAL(10, 2),

Quantity INT,

Discount DECIMAL(3, 2)

);

INSERT INTO Order_Details (OrderDetailID, OrderID, ProductID, UnitPrice, Quantity, Discount)

VALUES
(1, 21, 101, 50.00, 2, 0.10),

(2, 13, 102, 75.00, 1, 0.05),

(3, 24, 103, 100.00, 3, 0.15),

(4, 24, 104, 120.00, 1, 0.00);

You might also like