NCERT Solutions Chapter 8 MySQL IP Class 11 – Easy Guide

In this article, we are going to discuss NCERT Solutions Chapter 8 MySQL IP Class 11. Let’s start the article,
informatics practices class 11 ncert textbook solutions mysql!

NCERT Solutions Chapter 8 MySQL IP Class 11

Chapter 8 MySQL IP Class 11
Chapter 8 MySQL IP Class 11
  1. Match the following clauses with their respective functions.
ALTERInsert the values in a table
UPDATERestrictions on columns
DELETETable definition
INSERT INTOChange the name of a column
CONSTRAINTSUpdate existing information in a table
DESCDelete an existing row from a table
CREATECreate a database
NCERT Solutions Chapter 8 MySQL IP Class 11
NCERT Solutions Chapter 8 MySQL IP Class 11

The next question in Chapter 8 MySQL IP Class 11 or mysql class 11 ncert solutions is based on create a table and insert a data command.

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?
i) 30
ii) 1
iii) 3
iv) 4

Ans. iii) 3

b) What does ‘name’ represent in the above code snippet?
i) a table
ii) a row
iii) a column
iv) a database

Ans. iii) a column


c) What is true about the following SQL statement?
SelecT * fROM student;
i) Displays contents of table ‘student’
ii) Displays column names and contents of table ‘student’
iii) Results in error as improper case has been used
iv) Displays only the column names of table ‘student’

Ans.: ii) Displays column names and contents of table ‘student’


d) What will be the output of following query?
INSERT INTO student
VALUES (“Suhana”,109,’F’),
VALUES (“Rivaan”,102,’M’),
VALUES (“Atharv”,103,’M’),
VALUES (“Rishika”,105,’F’),
VALUES (“Garvit”,104,’M’),
VALUES (“Shaurya”,109,’M’);
i) Error
ii) No Error
iii) Depends on compiler
iv) Successful completion of the query

Ans.: i) Error

e) In the following query how many rows will be deleted?
DELETE student
WHERE student_id=109;
i) 1 row
ii) All the rows where student ID is equal to 109
iii) No row will be deleted
iv) 2 rows

Ans.: ii) All the rows where student ID is equal to 109

The next question in Chapter 8 MySQL IP Class 11 is fill in the blanks.

3. Fill in the blanks:

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

Ans.: Primary Key

b) The symbol Asterisk (*) in a select query retrieves __.

i) All data from the table

ii) Data of primary key only

iii) NULL data

iv) None of the mentioned

Ans. i) All data from the table

The following questions are based on table and queries in the Chapter 8 MySQL IP Class 11 or
class 11 ip ncert solutions.

4. Consider the following MOVIE database and answer the SQL queries based on it.

MovieIDMovieNameCategoryReleaseDateProductionCostBusinessCost
001Hindi_MovieMusical2018-04-23124500130000
002Tamil_MovieAction2016-05-17112000118000
003English_MovieHorror2017-08-06245000360000
004Bengali_MovieAdventure2017-01-0472000100000
005Telugu_MovieAction100000
006Punjabi_MovieComedy30500

a) Retrieve movies information without mentioning their column names.

Ans.:

select * from movie;


b) List business done by the movies showing only MovieID, MovieName and BusinessCost.

Ans.:

select movieid,moviename,businesscost from movie where businesscost is not null;


c) List the different categories of movies.

Ans.:

select distinict(category) from movie;


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.:

select movieid,moviename, businesscost-productioncost as 'NetProfit' from movie;
  • The NetProfit column is not a part of movie relation.
  • Such column names are known as alias names.
  • If the profit has not released yet then it can be considered as NULL
  • No, the query result doesn’t show profit as zero.

e) List all movies with ProductionCost greater than 80,000 and less than 1,25,000 showing ID, Name and ProductionCost.

Ans.:

select movieid,moviename,productioncost from movie where productioncost>80000 and productioncost<125000;

OR

select * from movie where productioncost between 80000 and 125000;

f) List all movies which fall in the category of Comedy or Action.

Ans.:

select * from movie where category='Comedy' or category='Action';

OR

select * from movie where category in ('Comedy','Action');

g) List the movies which have not been released yet.

Ans.:

select * from movide where releasedate is null;

The next section of Chapter 8 MySQL IP Class 11 is based on create database and fetching records.

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:

a) Create a database “Sports”.

Ans.:

create database sports;
use sports;


b) Create a table “TEAM” with following considerations:
i) It should have a column TeamID for storing an integer value between 1 to 9, which refers to unique identification of a team.
ii) Each TeamID should have its associated name (TeamName), which should be a string of length not less than 10 characters.

Ans.:

create table team
(teamid int(1),
teamname varchar(10));

c) Using table level constraint, make TeamID as primary key.

Ans.:

alter table team add primary key (teamid);


d) Show the structure of the table TEAM using SQL command.

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)

insert into team values (1,'Team Titan');
insert into team values (2,'Team Rockers');
insert into team values (3,'Team Magnet');
insert into team values (4,'Team Hurricane');


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.

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.

MatchIDMatchDateFirstTeamIDSecondTeamIDFirstTeamScoreSecondTeamScore
M12018-07-17129086
M22018-07-18344548
M32018-07-19137856
M42018-07-19245667
M52018-07-20143287
M62018-07-21236751
create table MATCH_DETAILS
(matchid char(2) primary key,
matchdate date,
firstteamid int(1) references team,
secondteamid int(1) references team,
firstteamscore int(2),
secondteamscore int(2));

insert into match_details values ('M1','2018-07-17',1,2,90,86);
insert into match_details values ('M2','2018-07-18',3,4,45,48);
insert into match_details values ('M3','2018-07-19',1,3,78,56);
insert into match_details values ('M4','2018-07-19',2,4,56,67);
insert into match_details values ('M5','2018-07-20',1,4,32,87);
insert into match_details values ('M6','2018-07-21',2,3,67,51);

This question is based on queries for Chapter 8 MySQL IP Class 11.

6. 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.

Ans.:

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);

Watch this video for video explanation of Chapter 8 MySQL IP Class 11:

7 Differentiate between the following commands:
a) ALTER and UPDATE
b) DELETE and DROP

AlterUpdate
This command is used to modify the table structure.This command is used to modify the table contents.
This is a DDL command.This is a DML command.
It will add, modify or drop any column or constraints.It will set new values to the already exists values in a table.
Example:
alter table emp add column remarks varchar(20);
Example:
update emp set sal=5000 where empno=1256;
Delete Drop
Delete is used to remove the rows from the table.Drop is used to deleting a table.
Delete is the DML command.Drop is DDL command.
Example:
delete from emp where empno=1245;
Example:
drop table emp;
  1. Create a database called STUDENT_PROJECT having the following tables. Choose appropriate data type and apply the necessary constraints.
Chapter 8 MySQL IP Class 11 - Q-8
Chapter 8 MySQL IP Class 11 – Q-8
create database stduent_project;

use student_project;

create table project
(project_id varchar(10) primary key,
projectname varchar(20) not null,
submissiondate date,
teamsize int(2),
guideteacher varchar(20));


create table project_assigned
(registration_id varchar(10) primary key,
project_id varchar(10) references project,
assigndate date);

create table student
(rollno int(4) primary key,
name varchar(20),
stream varchar(15) not null check(stream in('Science','Commerce','Humanities')),
section char(2) not null check(section in('I','II')),
registration_id varchar(10) references project_assigned);

a) Populate these tables with appropriate data.

Ans.:

insert into project values(1,'Library Management','2020-12-15',3,'Sanjay Sir');

insert into project_assigned values('XI-A012021',1,'2020-04-08');

insert into student values(1101,'Palak Shah','Science','I','XI-A012021');

b) Write SQL queries for the following:

c) Find the names of students in Science Stream.

Ans.:

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:

TablePrimary Key
Projectproject_id
project_assignedregsitrations_id
studentrollno

e) What are the foreign keys of the three relations?

Ans.: The following are the foreign keys for three relations:

RelationForeign Key
project_assignedproject_id
studentregistration_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.

select student.name,project.guideteacher from student, project where student.stream='Commerce' and project.guideteacher='Sanjay Sir'
  1. 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.

Ans.:

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;
  1. 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.

uniform and pirce table
uniform and price table

Ans.:

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.

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.

insert into uniform values(7,'Handkerchiefs','Red');
insert into cost (UCode,Price) values(7,100);

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)

I hope you enjoyed this video, if you have any doubt or query, feel free to ask in the comment section. Thank you for reading this article.

Leave a Reply