Structed Query Language: Questions Answer
Structed Query Language: Questions Answer
Structed Query Language: Questions Answer
Restrictions on
UPDATE
columns
Update existing
CONSTRAINTS information in a
table
Delete an existing
DESC
row from a table
Ans. iii) 3
Ans.: i) Error
a) ___________ declares that an index in one table is related to that in another table.
i) Primary Key
ii) Foreign Key
iii) Composite Key
iv) Secondary Key
4. Consider the following MOVIE database and answer the SQL queries based on it.
Ans.:
b) List business done by the movies showing only MovieID, MovieName and BusinessCost.
Ans.:
Ans.:
d) Find the net profit of each movie showing its ID, Name and Net Profit.
(Hint: Net Profit = BusinessCost – ProductionCost)
Make sure that the new column name is labelled as NetProfit. Is this column now a part of
the MOVIE relation. If no, then what name is coined for such columns? What can you say
about the profit of a movie which has not yet released? Does your query result show profit
as zero?
Ans.:
e) List all movies with ProductionCost greater than 80,000 and less than 1,25,000 showing
ID, Name and ProductionCost.
Ans.:
Ans.:
Ans.:
Ans.:
Ans.:
Ans.:
Ans.:
desc team;
e) As per the preferences of the students four teams were formed as given below. Insert
these four rows in TEAM table:
Row 1: (1, Team Titan)
Row 2: (2, Team Rockers)
Row 3: (3, Team Magnet)
Row 4: (4, Team Hurricane)
g) Now create another table below. MATCH_DETAILS and insert data as shown in the
table. Choose appropriate domains and constraints for each attribute.
Table: MATCH_DETAILS
h) Use the foreign key constraint in the MATCH_DETAILS table with reference to the
TEAM table so that the MATCH_DETAILS table records score of teams existing in the
TEAM table only.
M1 2018-07-17 1 2 90 8
M2 2018-07-18 3 4 45 4
M3 2018-07-19 1 3 78 5
M4 2018-07-19 2 4 56 6
M5 2018-07-20 1 4 32 8
M6 2018-07-21 2 3 67 5
Ans.:
c) Find out the MatchID and date of matches played by Team 1 and won by it.
d) Find out the MatchID of matches played by Team 2 and not won by it.
e) In the TEAM relation, change the name of the relation to T_DATA. Also, change the
attributes TeamID and TeamName to T_ID and T_NAME respectively.
Way 1
alter table t_data rename column teamid to t_id;
alter table t_data rename column teamname to t_name;
Way 2
alter table t_data change teamid t_id int(1);
alter table t_data change teamname t_name varchar(20);
7 Differentiate between the following commands:
a) ALTER and UPDATE
b) DELETE and DROP
Alter Update
Delete Drop
Example: Example:
delete from emp where empno=1245; drop table emp;
Ans.:
Ans.:
Ans.: The following are the primary keys for three tables:
Project project_id
project_assigned regsitrations_id
student rollno
e) What are the foreign keys of the three relations?
Ans.: The following are the foreign keys for three relations:
student registration_id
f) Find names of all the students studying in class ‘Commerce stream’ and are guided by
the same teacher, even if they are assigned different projects.
Ans.:
d) Find names of employees working in a department, say, ‘SALES’ and having exactly
two dependents.
a) The PRICE relation has an attribute named Price. In order to avoid confusion, write
SQL query to change the name of the relation PRICE to COST.
Ans.:
Ans.:
Its not possible to insert records into cost table. If you want to do that you must insert record in
the uniform table.
c) When you used the above query to insert data, you were able to enter the values for
handkerchief without entering its details in the UNIFORM relation. Make a provision so
that the data can be entered in COST table only if it is already there in UNIFROM table.
d) Further, you should be able to assign a new UCode to an item only if it has a valid UName. Write a query
to add an appropriate constraint to the SCHOOL_UNIFORM database.
alter table uniform add constraint check (UName is not null)