SQL Assignment MBA I

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

SQL

Assignment 1
a. Write an SQL command that will create a table named TableOne with the following
fields and types: ENo int, FirstName VARCHAR(24), PAddress VARCHAR(30), Age
int , Giftvalue NUMERIC(10,2).
b. Insert the following items in the table you have created

ENo FName PAddress Age Giftvalue

01 Ram Dwarka sector 41 200


10

02 Sita Janakpuri 26 250


block C

03 Rajesh Dwarka sector 23 200


15

04 Ajit Noida sector 35 150


11

05 Rita Noida sector 40 200


11

Assignment 2: Select Queries for table TableOne


a. Write an SQL query to display all the records
b. Write an SQL query to display all the records where age >40
c. Write an SQL query to display Fname, Age from the table
d. Write an SQL query to display Fname, Age, Gift where Age > 35 from the table
e. Write an SQL query to display all record where Gift > 200 and Age >20
f. Write an SQL query to display all record where Gift > 200 or Age >20

Assignment 3: Queries for aggregate functions for table TableOne


a. Write SQL query to add the age of all records.
b. Write a query to average of the cost of gifts.
c. Write a query to display the name and age of the youngest member
d. Write a query to count the number of candidates whose age in more than 30.
e. Write a query to find the name and cost of the costliest gift.
Assignment 4: Constraints

a. Create a table TableTwo with the following specifications

Field name Data type

EMPID INT, Primary Key

DEPT CHAR(5)

EMPNAME VARCHAR(15)

PADDRESS VARCHAR(30)

SALARY NUMERIC(7)

b. Make the following entries in the table

EMPID DEPT EMPNAME PADDRESS SALARY

101 RD01 Prince Park Way 15000

102 RD01 Harry Pebble Street 12000

103 RD02 Tom Rose Garden 11000

104 RD02 Susan Model Town 10000

105 ED01 Mark Victor Crescent 10000

106 AD01 Francis Chelmsford Park 13000

107 GR01 Robert Downtown 14000


Cross

108 RD03 Philip Park Avenue 15000

109 RD03 Henry Malibu Beach 14000

110 AD01 Frank St. Peters Lane 7000

Assignment 5: Select & Update


a. Find names for all employees who work for the RD01 department.
b. How many employees work in department starting from RD.
c. What is the maximum and minimum of the salaries.
d. Name the employees and their department whose salaries are greater than 12000.
e. Find the number of employees in each department.
f. List the employees in increasing order of their salaries.
g. Modify the table so that Susan is assigned to AD01 department.
h. Change the salary of all the employees to AD01 to salary*1.2
i. Name the employee in department RD03 who lives in Park Avenue.
j. Find the Average salary.
k. Count the number of employees.

Assignment 6: Alter
Create a table Student1 with the following structure:
Roll no number 3
Name varchar 20
Marks number 6
Write the following SQL queries
1. Add new columns pincode and city to Student1
2. Change the width of pincode to 6
3. Add a primary key
4. Add a not null constraint
5. Add construct check to the Marks column (Marks >=0 and Marks<=100)

You might also like