Examples
Examples
Write a query
statement to insert data from table NewEmpl into EMPL where salary and
comm is more than Rs. 4000.
2. Insert all those records of table Accounts into table Pending where
amt_outstanding is more than 10000.
3. To view all the details (all columns and rows) of the "employee" table the
below query is executed :
4. Give commission of Rs.500 to all employees who joined in year 1982
(table Empl).
Answer
Table Empl
Answer
Table employee
6.Modify table Empl, add another column called Grade of VARCHAR type, size
1 into it.
7.
Add a constraint (NN-Grade) in table Empl that declares column Grade not null.
8.Modify the definition of column Grade. Increase its size to 2.
10.Create the table Department table based on the following table instance chart.
11.Populate the table Department with data from table dept. Including only
required columns.
12.Create the table Employee based on the following table instance chart.
ID NUMBER 8
First_Name VARCHAR 25
Last_Name VARCHAR 25
Dept_ID NUMBER 8
First_Name VARCHAR 25
Last_Name VARCHAR 25
Dept_ID NUMBER 8
Cust_ID NUMBER 7
Cust_Name VARCHAR 30
Cust_Address1 VARCHAR 20
Column Name Data Type Length
Cust_Address2 VARCHAR 30
Pincode NUMBER 6
Cust_Phone VARCHAR 10
Cust_Name VARCHAR 30
Cust_Address1 VARCHAR 20
Cust_Address2 VARCHAR 30
Pincode NUMBER 6
Cust_Phone VARCHAR 10
15.Add one column Email of data type VARCHAR and size 30 to the table
Customer.
Nulls/
NOT NULL
Unique
Departme
Fk Table
nt
Fk Column Dept_ID
Length 6 20 30 10 9, 2 2
22.Consider the following MOVIE table and write the SQL queries based on it.
MovieI MovieNam Categor ReleaseDat ProductionC BusinessCos
D e y e ost t
Hindi_Movi
001 Musical 2018-04-23 124500 130000
e
Tamil_Mov
002 Action 2016-05-17 112000 118000
ie
English_Mo
003 Horror 2017-08-06 245000 360000
vie
Bengali_M Adventu
004 2017-01-04 72000 100000
ovie re
Telugu_Mo
005 Action - 100000 -
vie
Punjabi_Mo
006 Comedy - 30500 -
vie
(b) List business done by the movies showing only MovieID, MovieName and
Total_Earning. Total_Earning to be calculated as the sum of ProductionCost and
BusinessCost.
(c) List the different categories of movies.
(d) Find the net profit of each movie showing its MovieID, MovieName and
NetProfit. Net Profit is to be calculated as the difference between Business Cost
and Production Cost.
(e) List MovieID, MovieName and Cost for all movies with ProductionCost
greater than 10,000 and less than 1,00,000.
(f) List details of all movies which fall in the category of comedy or action.
(g) List details of all movies which have not been released yet.
23.Suppose your school management has decided to conduct cricket matches
between students of Class XI and Class XII. Students of each class are asked to
join any one of the four teams – Team Titan, Team Rockers, Team Magnet and
Team Hurricane. During summer vacations, various matches will be conducted
between these teams. Help your sports teacher to do the following:
(c) Using table level constraint, make TeamID as the primary key.
(d) Show the structure of the table TEAM using a SQL statement.
(e) As per the preferences of the students four teams were formed as given below.
Insert these four rows in TEAM table:
(f) Show the contents of the table TEAM using a DML statement.
(g) Now create another table MATCH_DETAILS and insert data as shown
below. Choose appropriate data types and constraints for each attribute.
Table: MATCH_DETAILS
M1 2018-07-17 1 2 90 86
FirstTea SecondTeamI FirstTeamSc SecondTeamSc
MatchID MatchDate
mID D ore ore
M2 2018-07-18 3 4 45 48
M3 2018-07-19 1 3 78 56
M4 2018-07-19 2 4 56 67
M5 2018-07-18 1 4 32 87
M6 2018-07-17 2 3 67 51
(a) Display the MatchID of all those matches where both the teams have scored
more than 70.
(b) Display the MatchID of all those matches where FirstTeam has scored less
than 70 but SecondTeam has scored more than 70.
(c) Display the MatchID and date of matches played by Team 1 and won by it.
(d) Display the MatchID of matches played by Team 2 and not won by it.
(e) Change the name of the relation TEAM to T_DATA. Also change the
attributes TeamID and TeamName to T_ID and T_NAME respectively.
25.A shop called Wonderful Garments who sells school uniforms maintains a
database SCHOOLUNIFORM as shown below. It consisted of two relations -
UNIFORM and COST. They made UniformCode as the primary key for
UNIFORM relations. Further, they used UniformCode and Size to be composite
keys for COST relation. By analysing the database schema and database state,
specify SQL queries to rectify the following anomalies.
(a) M/S Wonderful Garments also keeps handkerchiefs of red colour, medium
size of Rs. 100 each.
(b) INSERT INTO COST (UCode, Size, Price) values (7, 'M', 100);
When the above query is used to insert data, the values for the handkerchief
without entering its details in the UNIFORM relation is entered. Make a
provision so that the data can be entered in the COST table only if it is already
there in the UNIFORM table.
(c) Further, they should be able to assign a new UCode to an item only if it has a
valid UName. Write a query to add appropriate constraints to the
SCHOOLUNIFORM database.
(d) Add the constraint so that the price of an item is always greater than zero.
(a) Create the table Product with appropriate data types and constraints.
(e) Calculate the value of the discount in the table Product as 10 per cent of the
UPrice for all those products where the UPrice is more than 100, otherwise the
discount will be 0.
(f) Increase the price by 12 per cent for all the products manufactured by Dove.
Write the output(s) produced by executing the following queries on the basis of
the information given above in the table Product:
27.Using the CARSHOWROOM database given in the chapter, write the SQL
queries for the following:
(b) Set appropriate discount values for all cars keeping in mind the following:
(c) Display the name of the costliest car with fuel type "Petrol".
(d) Calculate the average discount and total discount available on Baleno cars.
(e) List the total number of cars having no discount.
Table inventory