DDL command worksheet no 3
DDL command worksheet no 3
DDL command worksheet no 3
Informatics Practices
My SQL Worksheet-3
(DDL – Alter Table commands)
1. Sohan created a table in Mysql. Later on he found that there should have been another column in
the table. Which command should he use to add another column to the table?
2. While creating a table 'Customer' Simrita forgot to set the primary key for the table. Give the
statement which she should write now to set the column 'CustiD' as the primary key of the table?
Now she wants to add a new column ‘Address’ to the above given table. Suggest suitable MySQL
command for the same.
4. Write SQL command to remove column named ‘Hobbies’ from a table named ‘Student’.
5. While creating the table Student last week, Ms. Sharma forgot to include the column Game Played.
Now write a command to insert the Game Played column with VARCHAR data type and 30 size into
the Student table?
7. Rashi wants to add another column ‘Hobbies’ with datatype and size as VARCHAR(50) in the already
existing table ‘Student’. She has written the following statement. However it has errors. Rewrite
the correct statement.
MODIFY TABLE Student Hobbies VARCHAR;
8. Ms. Shalini has just created a table named “Employee” containing columns
Ename, Department, Salary.
After creating the table, she realized that she has forgotten to add a primary key column in the
table. Help her in writing SQL command to add a primary key column empid. Also state the
importance of Primary key in a table.
10. Mr. Akshat have added a not null constraint to the “name” field in “employees” table. But now he
wants to remove that not null constraint. Write the command to delete the not null constraint
from name field.
11. CREATE TABLE student ( name CHAR(30), student_id INT, gender CHAR(1), PRIMARY KEY
(student_id) ); a) What will be the degree of student table?
i) 30 ii) 1 iii) 3 iv) 4
12. b) What does ‘name’ represent in the above code snippet?
i) a table ii) a row iii) a column iv) a database
18. b) List business done by the movies showing only MovieID, MovieName and BusinessCost.
21 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?
22 e) List all movies with ProductionCost greater than 80,000 and less than 1,25,000 showing ID,
Name and ProductionCost.
29 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)
31 Using the sports database containing two relations (TEAM, MATCH_DETAILS), answer the
following relational algebra queries.
a) Retrieve the MatchID of all those matches where both the teams have scored > 70.
33 c) Find out the MatchID and date of matches played by Team 1 and won by it.
34 d) Find out the MatchID of matches played by Team 2 and not won by it.
35 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.
Extra Notes