NCERT solutions of Introduction To Structured Query Language (SQL)
Match the following clauses with their respective functions.
1.ALTER | i) Insert the values in a table |
2.UPDATE | ii) Restrictions on columns |
3.DELETE | iii) Table definition |
4.INSERT INTO | iv) Change the name of a column |
5.CONSTRAINTS | v) Update existing information in a table |
6.DESC | vi) Delete an existing row from a table |
7.CREATE | vii) Create a daatabase |
1 – iv | |
2. Choose appropriate answer with respect to the following code snippet. 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? | |
Ans. iii) 3 | |
b) What does ‘name’ represent in the above code snippet? | |
Ans. iii) a column | |
c) What is true about the following SQL statement? | |
Ans.: ii) Displays column names and contents of table ‘student’ | |
d) What will be the output of following query? | |
Ans.: i) Error | |
e) In the following query how many rows will be deleted? | |
Ans.: ii) All the rows where student ID is equal to 109 | |
3. Fill in the blanks: | |
Ans.: Primary Key | |
b) The symbol Asterisk (*) in a select query retrieves __. | |
Ans. i) All data from the table | |
4. Consider the following MOVIE database and answer the SQL queries based on it. a) Retrieve movies information without mentioning their column names. | |
select * from movie; | |
b) List business done by the movies showing only MovieID, MovieName and BusinessCost. | |
select movieid,moviename,businesscost from movie where businesscost is not null; | |
c) List the different categories of movies. | |
select distinict(category) from movie; | |
d) Find the net profit of each movie showing its ID, Name and Net Profit. | |
select movieid, moviename, businesscost-productioncost as ‘NetProfit’ from movie; | |
e) List all movies with ProductionCost greater than 80,000 and less than 1,25,000 showing ID, Name and ProductionCost. | |
select movieid,moviename,productioncost from movie where productioncost>80000 and productioncost<125000; | |
f) List all movies which fall in the category of Comedy or Action. | |
select * from movie where category=’Comedy’ or category=’Action’ ; | |
g) List the movies which have not been released yet. | |
select * from movide where releasedate is null; NCERT solutions MySQL | |
5. 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: | |
create database sports; use sports; | |
b) Create a table “TEAM” with following considerations: | |
create table team (teamid int(1), teamname varchar(10)); | |
c) Using table level constraint, make TeamID as primary key. | |
alter table team add primary key (teamid); | |
d) Show the structure of the table TEAM using SQL command. | |
desc team; | |
e) As per the preferences of the students four teams were formed as given below. Insert these four rows in TEAM table: | |
insert into team values (1,’Team Titan’); | |
f) Show the contents of the table TEAM. | |
select * from team; | |
g) Now create another table below. MATCH_DETAILS and insert data as shown in the table. Choose appropriate domains and constraints for each attribute. | |
create table MATCH_DETAILS | |
6. Using the sports database containing two relations (TEAM, MATCH_DETAILS), answer the following relational algebra queries. | |
select matchid from match_details where firstteamscore >70 and secondteamscore>70; | |
b) Retrieve the MatchID of all those matches where FirstTeam has scored < 70 but SecondTeam has scored > 70. | |
select matchid from match_details where firstteamscore<70 and secondteamscore>70; | |
c) Find out the MatchID and date of matches played by Team 1 and won by it. | |
select matchid, matchdate from match_details where firstteamid=1 and firstteamscore>secondteamscore; | |
d) Find out the MatchID of matches played by Team 2 and not won by it. | |
select matchid, matchdate from match_details where firstteamid=2 and firstteamscore<secondteamscore; | |
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. | |
rename table team to t_data; 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: | |
Alter | |
| |
Delete | |
NCERT solutions MySQL8. Create a database called STUDENT_PROJECT having the following tables. Choose appropriate data type and apply the necessary constraints. | |
create database stduent_project; | |
a) Populate these tables with appropriate data. | |
insert into project values(1,’Library Management’,’2020-12-15′,3,’Sanjay Sir’); | |
b) Write SQL queries for the following: c) Find the names of students in Science Stream. | |
select name from student where stream=’science’; | |
d) What will be the primary keys of the three tables? | |
Ans.: The following are the primary keys for three tables: | |
e) What are the foreign keys of the three relations? | |
Ans.: The following are the foreign keys for three relations: | |
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. | |
select student.name,project.guideteacher from student, project where student.stream=’Commerce’ and project.guideteacher=’Sanjay Sir’ | |
NCERT solutions MySQL9.An organization ABC maintains a database EMPDEPENDENT to record the following details about its employees and their dependents. EMPLOYEE(AadhaarNo, Name, Address, Department,EmpID) DEPENDENT(EmpID, DependentName, Relationship) Use the EMP-DEPENDENT database to answer the following SQL queries: a) Find the names of employees with their dependent names. | |
select employee.name,dependent.name from employee,dependent; | |
b) Find employee details working in a department, say, ‘PRODUCTION’. | |
select * from employee where department=’Production’; | |
c) Find employee names having no dependent. | |
select employee.name from employee, dependent where employee.empid is null; | |
d) Find names of employees working in a department, say, ‘SALES’ and having exactly two dependents. | |
select employee.name from employee,dependent where employee.department=’sales’ and count(dependent.empid)=2; | |
A shop called Wonderful Garments that sells school uniforms maintain a database SCHOOL_UNIFORM as shown below. It consisted of two relations — UNIFORM and PRICE. They made UniformCode as the primary key for UNIFORM relation. Further, they used UniformCode and Size as composite keys for PRICE relation. By analysing the database schema and database state, specify SQL queries to rectify the following anomalies. 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. | |
rename table price to cost; | |
b) M/S Wonderful Garments also keeps handkerchiefs of red color, medium size of `100 each. Insert this record in COST table | |
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. | |
insert into uniform values(7,’Handkerchiefs’,’Red’); | |
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)
| |
No comments:
Post a Comment
Have query? Just say it.