0% found this document useful (0 votes)
29 views14 pages

MYSQLAssignments Solutions

The document provides solutions to various SQL queries and questions. It includes: 1) Solutions to queries on a PRODUCT table including finding max, min, average and total prices, counts, and sums. 2) Explanations of concepts like degree and cardinality of a table, errors in SQL queries, differences between DROP and DELETE, ALTER and UPDATE. 3) Solutions to additional questions testing knowledge of aggregate functions, ORDER BY, COUNT, GROUP BY, DISTINCT, LIKE operator and more. 4) Explanations of ALTER TABLE, DROP TABLE, DELETE, and other DDL and DML commands.

Uploaded by

Pinchu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views14 pages

MYSQLAssignments Solutions

The document provides solutions to various SQL queries and questions. It includes: 1) Solutions to queries on a PRODUCT table including finding max, min, average and total prices, counts, and sums. 2) Explanations of concepts like degree and cardinality of a table, errors in SQL queries, differences between DROP and DELETE, ALTER and UPDATE. 3) Solutions to additional questions testing knowledge of aggregate functions, ORDER BY, COUNT, GROUP BY, DISTINCT, LIKE operator and more. 4) Explanations of ALTER TABLE, DROP TABLE, DELETE, and other DDL and DML commands.

Uploaded by

Pinchu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Solution of Assignment 3

Q1 Write the output of the following on the basis of given table: Product

Pid P_name Price Qty


1 P1 240 23
2 P2 300 24
3 P3 320 43
4 P4 130 32
5 P5 100 17

(a) select max(price) from product;


(b) select avg(price) from product;
(c) select min(qty) from product;
(d) select count(*) from product;
(e) select count(qty) from product;
(f) select distinct(price) from product;
(g) select count(distinct(price)) from product;
(h) select price*qty from product;
(i) select sum(price) from product;
(j) select sum(price) from product where qty>30;

Ans

(a) 320
(b) 218
(c) 17
(d) 5
(e) 5
(f) 240
300
320
130
100
(g) 5
(h) 5520
7200
13760
4160
1700
(i) 1090
(j) Error

Q2

(a) what is the degree and cardinality of table who has 10 columns and 10 rows?
Ans degree -6 and cardinality-10
(b) identify the errors in the following query
(i) select * from student where name=NULL;
Ans select * from student where name is NULL;

(ii) select max(salary) from employee group by designation where DOJ>”2020-02-02”;


Ans select max(salary) from employee group by designation having DOJ>”2020-02-
02”;

(iii) select * from student where name is =”Amit”;


Ans select * from student where name =”Amit”;

(iv) select * from employee where salary between 1000,2000;


Ans select * from employee where salary between 1000 and 2000;
(v) select * from employee where name=”A%”;
Ans select * from employee where name like ”A%”;
(vi) select name,subject from student where average>20 and <30;
Ans select name,subject from student where average>20 and average<30;
(vii) select * from student where name=”Amit” and name=”Sumit”;
Ans select * from student where name=”Amit” or name=”Sumit”;
(viii) select highest(salary) from employee;
Ans select max(salary) from employee;
(ix) select all from student;
Ans select * from student;
(x) update table student set name=”sunita where admno=1234;
Ans update student set name=”sunita where admno=1234;

Q3 What is the difference between drop and delete command?

Ans drop command delete the data as well as structure of table permanently from database while
delete command delete only the data from the table.

Q4 Differentiate between alter and update command.

Ans alter command is used to change the structure of table and update command is used to modify the
data of table.

Q5 what is group by clause?

Ans This clause is used to arrange same data in groups using some functions like sum, average etc

Q6 write the output of the following:

(a) select 75+3*2 ans 81


(b) select 23+56%5 ans 24
(c) select power(2,3) ans 8
(d) select round(10.237,2) ans 10.24
(e) select round(12.3454,2) ans 12.35
(f) select round(12.3444,2) ans 12.34

Q7 write the query on the basis of the following table:STUDENT

Name,admno,subject,average,position

(a) display all records in ascending order


Ans select * from student order by name;
(b) display details of student whose position is “First” and average greater than 70.
Ans select * from student where position =”First and average>70;
(c) display details of “Amit”,”Sumit” and “Ashish”(using IN operator)
Ans select * from student where name in(“Amit”,”Sumit” ,“Ashish”);
(d) display name and subject of student whose position is “First”
Ans select name,subject from student where position=”First”;
(e) Display the total number of records present in above table.
Ans select count(*) from student;
(f) Display the maximum average;
Ans select max(average) from student;
(g) Display name of the student who got maximum average.
Ans Select name,max(average) from student;
(h) Insert the following record:
“Shikha”,1221,”Physics”,70,”Second”
Ans Insert into student values(“Shikha”,1221,”Physics”,70,”Second”);

Q8 What do you mean by aggregate function?

Ans A function which work on multiple values and return a single value.

Q9 Which keyword is used to arrange records in increasing or decreasing order?

Ans order by

Q10 Which function returns the total number of records in a table?

Ans count()

Q11 select count(*) form student; return 5

Select count(fee) from student; return 4

Why different output in above two queries?

Ans different output shows that there must be one null value in a column fee.

Q12 _____________function returns the average value of a numeric column. Ans avg()

Q13 Which function returns the sum of numeric column?

Ans sum()

Q14 ____________keywords removes duplicates records from the table.


Ans distinct

Q15 Write a query to display all the records of table student whose name starts from “A”

Ans select * from student where name like “A%”;

Q16 Which function return the minimum value from column fee of table student?

Ans min()

#-----------------------------------------------------------------------------------------------------------
Solution of Assignment 4
Q1 Write the output of the following:

Select 76+75%4 from dual;

Ans 79

Q2 Write the queries of the following:

Table : student

Rollno Name Class Fee Percentage


1 Amit X 3400 78
2 Sumit XI 2800 45
3 Suman X 3700 84
4 Pushkar IX 2500 60

(a) Display all the records of table student.


(b) Display roll number,name and class of table student.
(c) Display records of students of class x.
(d) Display details of sumit.
(e) Display records of student paying fees less than 3000.
(f) Display fee of Amit.
(g) Display Class and percentage of Pushkar.
(h) Delete record of Amit.
(i) Display the structure of table student.
(j) Insert the following record in table student
5,”Suman”,’X’,3000,70

Ans

(a) select * from student;


(b) select rollno,name,class from student;
(c) select * from student where class=’X’;
(d) select * from student where name=”Sumit”;
(e) select * from student where fee<3000;
(f) select fee from student where name=”Amit”;
(g) select class, percentage from student where name=”Pushkar”;
(h) delete from student where name=”Amit”;
(i) desc student;
(j) insert into student values(5,”Suman”,’X’,3000,70);

#---------------------------------------------------------------------------------------------------------
Solution of Assignment 5

Q1 Which command is used to delete data from the table?

Ans Delete

Q2 Which command is used to add column in a table?

Ans Alter

Q3 Write a query to add the column DOB of data type date in the table student.

Ans alter table student add DOB date;

Q4 Write a query to add new column “Grade” of data type varchar(2) in table “student” with default
value “A”

Ans alter table student add(Grade char(2) default “A”);

Q5 Write a query to change the data type of above added column(Grade) to varchar(4).

Ans alter table student modify(Grade varchar(4));

Q6 Write a query to delete column Grade from table student.

Ans Alter table student drop Grade;

Q7 ___________command is used to delete table completely/permanently.

Ans Drop Table

Q8 Write a query to delete the table “Emp”permanently.

And Drop table Emp;

Q9 Delete from emp;

The above command will delete all the records from table “emp”.(True/False)

Ans True

Q10 Write a query to display all the records from table “Student”

Ans select * from student;

#---------------------------------------------------------------------------------------------------------------------------

Solution of Assignment 6

Q1 _______________ command is used to remove database completely.

Ans drop
Q2 which command is used to show the structure of the table.

Ans desc or describe

Q3 Name the columns which are visible when we execute the following command desc book;

Ans columns are

Field type Null, key, default,extra

Q4 Write the command to create the following table: “Student”

Fieldname Data type Constraint

Rollno Integer(5) Primary Key

Sname Varchar(30)

Contactno Char(10) Not Null

Ans

Create tale student(Rollno integer(5) not null primary key, Sname varchar(30), Contactno char(10) not
null);

Q5 Write query to insert the following record in above created table.

Roll number -1, Name- Amit, Contact number – 1234567890

Ans insert into student values(1,”Amit”,”1234567890”)

Q6 Write a query to insert the following values only,

Roll number -2, Contact number – 11111111

Ans insert into student(Rollno,Contactno) values(2,’ 11111111’);

Q7 Is Null value is equivalent to zero?

Ans No

Q8 What do you mean by Null in MySQL?

Ans Null means a value which is unavailable or in other words we can say Null means no value.

Q9 Which command is used to modify data in table?

Ans update

Q10 Write a query to modify the Contactno to 98789878 whose roll number is 1 in table student.(gicen
above)

Ans update student set Contactno=’98789878’ where Rollno=1

#-----------------------------------------------------------------------------------------------------------------------------
Solution of Assignment 7

Q1

What do you mean by keyword in MySQL?

Ans Keyword refers to a word which has special meaning in MySQL.

Q2 Identify the keyword from the following query.

Select * from book;

Ans keywords are : select , from

Q3 All statements in MySQL is terminated by ___________.

Ans semicolon(;)

Q4 We can create ______________(database/tables) inside ____________(database/tables).

Ans tables, database

Q5 SQL is a case sensitive language(T/F).

Ans False

Q6 _____________statement is used to show all the existing databases in server.

Ans show databases;

Q7 Which statement is used to show all existing table in database.

Ans show tables

Q8 Write statement to open a database named “student”.

Ans. use student .

Q9 Name the command used to create database.

Ans create database.

Q10 Write statement to create database named “book”

Ans create database book;

#---------------------------------------------------------------------------------------------------------------
Solution of Assignment 8

Q1 In MySQL, date values to be enclosed in {} or in single quotation marks(True/False)

Ans True

Q2 _______________________is the format of date in MySQL.

Ans yyyy/mm/dd

Q3 Data type of “name” field in a table is char(25). How many bytes will be occupied by values “Ram”
and “Ramesh Kumar”?

Ans 25

Q4 Time data type is used to store time in _____________format.

Ans hh:mm:ss

Q5 varchar is a fixed length data type. (True/False)

Ans False

Q6 Name the command which is used to close MySQL.

Ans quit

Q7 Which data type in MySQL is used to store logical values?

Ans Boolean

Q8 Out of char,varchar and memo, which data type is used to store large amount of data?

Ans memo

Q9 Which data type in MySQL is used to store images , animations,clips etc

Ans BLOB or RAW

Q10 Write the appropriate data types for the following fields.

(a) Dateofbirth
(b) Salary
(c) Name
(d) Address
(e) Phonenumber

Ans

(a) Date
(b) Any numeric data type preferable numeric or decimal
(c) Char or varchar
(d) Char or varchar
(e) Char or numeric

#--------------------------------------------------------------------------------------------------------------
Solution of Assignment 9

Q1 Write two advantages of SQL

Ans

1. I tis very easy to learn


2. It is not a case sensitive language

Q2 MySQL is an ____________software. (open source/Proprietary)

Ans Open source

Q3 Name two types of SQL Commands.

Ans 1. DDL

2.DML

Q4 What is the difference between DDL and DML commands?

Ans

DDL DML
Data definition language Data manipulation language
These are used to perform tasks related to the These commands are used to manipulate data
structure of the table

Q5 Identify the DDL and DML commands from the following:

(a) Create
(b) Alter
(c) Insert
(d) Update
(e) Drop
(f) Delete
(g) Select
(h) Grant
(i) Revoke

Ans

(a) DDL
(b) DDL
(c) DML
(d) DML
(e) DDL
(f) DML
(g) DML
(h) DDL
(i) DDL

Q6 What do you mean by data type?

Ans Data type refers to the type of data we are entering in the column of the table.

Q7 Name two numeric data type in MySQL.

Ans integer and smallint

Q8 Name two string Data type in MySQL.

Ans Char and Varchar

Q9 Which data type is used for ‘Date of birth’ field in student table.

Ans Date

Q10 What is the difference between Char and Varchar.

Ans char is fixed length data type while varchar is variable length data type.

#------------------------------------------------------------------------------------------------------------
Solution of Assignment 10

Q1 Write Full form of DBMS.

Ans Database Management System

Q2 A group of rows and columns is called ______________

Ans table

Q3 Define the following terms

(a) Primary key


(b) Foreign Key
(c) Candidate key
(d) Alternate key

Ans

(a) A field which uniquely identified each and every record.


(b) Foreign key is a field (or collection of fields) in one table that refers to the primary key in
another table. It is used to link two tables.
(c) Those field which can act as a primary key are called candidates key.
(d) Candidates key is also called alternate key

Q4 Give two examples of DBMS software.

Ans Oracle, MS Access, MySQL

Q5 A primary key is one of the candidate key.( True/False)

Ans True

Q6 What do you mean by Degree and cardinality in DBMS?

Ans number of rows in a table is called cardinality

Number of columns in a table is called degree

Q7 What is the alternate name of column in table?

Ans attribute or field

Q8 What is the alternate name of row in table?

Ans record or tuple

Q9 Answer the following questions on the basis the given table.

Admno Name Gender Stipend Subject Average Division


101 Suresh Male 400 Maths 65.9 1
102 Anil Male 350 Physics 78.4 1
103 Laxmi Female 450 Bio 45.6 2
104 Lata Female 500 Physics 89.7 1
105 Suman Female 600 Bio 93.8 1
106 Jay Male 300 Maths 40.9 2
107 Kamal Male 250 Chemistry 66.0 1

(a) How many attributes are there in above table?


(b) How many tuples are there in above table?
(c) What is the degree of above table?
(d) What is the cardinality of above table?
(e) Name the primary key in the table/

Ans

(a) There are 7 attributes in the tables


(b) 7
(c) Degree- 7
(d) Cardinality -7
(e) admno

You might also like