MySql Revision Tour
MySql Revision Tour
Answer =
SQL COMMANDS ARE CLASSIFIED INTO:
DDL (Data Definition Language)
DML (Data Manipulation Language)
DQL (Data Query Language)
DCL (Data Control Language)
DML:-
1. It is Data Manipulation Language
2. It is used to manipulate the existing databases.
3. It is used for managing data within schema objects
4. Commands are: SELECT, INSERT, DELETE, UPDATE, MERGE, CALL
5. It works on one or more rows
6. It have where clause to filter records
7. Changes can be rolled back
8. It is further classified as procedural and non procedural
9. Example --- Select * from student
Q3(a) What is the use of UPDATE statement in SQL ? How is it different from ALTER
statement
(b) Mr. Shankar created a table VEHICLE with 3 rows and 4 columns. He added 1 more
row to it deleted one column. What is the Cardinality and Degree of the Table VEHICLE ?
(c) Consider the following table named "GYM" with details about fitness items being sold
in the store. Write command of SQL for (i) to (iv).
(i) To display the names of all the items whose name starts with "A".
(ii) To display ICODEs and INAMEs of all items, whose Brandname is Reliable or Coscore.
(iii) To change the Brandname to "Fit Trend India" of the item, whose ICODE as "G101".
(iv) Add a new row for new item in GYM with the details :
Answer =
(a)
The UPDATE statement in SQL is used to update the data of an existing table in database .
ALTER is a DDL (Data Definition Language) statement. Whereas UPDATE is a DML (Data
Manipulation Language) statement. ALTER is used to update the structure of the table (add/remove
field/index etc). Whereas UPDATE is used to update data.
(b)
number of cardinality = 4
Number of degree = 3
(c)
(i)
select INAME from GYM
Where INAME like “A%”
(ii)
select ICODE , INAME from GYM
Where BRANDNAME in ( “Reliable” , “Coscore” )
(iii)
update GYM
Set BRANDNAME = “Fit Trend India ”
Where ICODE = “G101”;
(iv)
insert into GYM values ("G107", "Vibro exerciser", 21000, "GTCFitness") ;
Q4. (a) Mr. James created a table CLIENT with 2 rows and 4 columns. He added 2 more
rows to it and deleted one column. What is the Cardinality and Degree of the Table
CLIENT ?
(b) Consider the following table FITNESS with details about fitness products being sold in
the store. Write command of SQL for (i) to (iv).>
(i) To display the names of all the products with price more than 20000.
(ii) To display the names of all products by the manufacturer "Aone".
(iii) To change the price data of all the products by applying 25% discount reduction.
(iv)To add a new row for product with the details
"P7", "Vibro Exerciser", 28000, "Aone".
Answer =
(a)
Cardinality = 4
Degree = 3
(b)
(i)
select PNAME from FITNESS
Where price > 20000;
(ii)
select pname from FITNESS
Where manufacturer = “Aone”;
(iii)
update FITNESS
Set price = price * 0.75 ;
(iv)
insert into FITNESS values (“P7” , “Vibro Exerciser”, 28000, "Aone" ) ;
Q5.Write SQL commands for the following on the basis
of given table CLUB.
(a) To show all information about the swimming coaches in the club.
(b) To list names of all coaches with their date of appointment (DATOFAPP) in
descending order.
(c) To display a report, showing coachname, pay, age and bonus (15% of pay) for
all the coaches.
Answer =
(a)
Select * from CLUB
Where sports = “SWIMMING”;
(b)
select coachname, datofapp from CLUB
Order by datofapp DESC;
Answer =
(a)
select * from student1
where stream = “Nonmedical” ;
(b)
select name from student
where class like “12%”
order by stipend ;
(c)
select * from student1
order by AvgMark desc
Answer =
A foreign key is a column or group of columns in a relational database table that provides a
link between data in two tables. It acts as a cross-reference between tables because it
references the primary key of another table, thereby establishing a link between them.
A FOREIGN KEY is a field (or collection of fields) in one table that refers to the PRIMARY
KEY in another table.
Foreign key ( <column name>) REFERENCES <parent table name > ( < Column name > )
Answer =
1. Primary key can not accept null values . while foreign key can accept multiple null
values .
2. only one primary key in a table while more than one foreign key in a table .
3. primary key uniquely identify a record in the table while foreign key is a field in the table
that is primary key in another table
The two basic type of constraints are Column constraints and table constraints. The
difference between the two is that column constraints apply only to individual columns ,
whereas table constraints apply to group of one or more columns.
Answer =
Create table Pending Select * from Accounts where amt_outstanding > 10000 ;
Q12. Increase salary of employee records by 10% (table
employee).
Answer =
Update employee
Set salary = salary + salary * 0.10 ;
Q13. Add a constraint (NN-Grade) in table Empl (given
before assignment) that declares column Grade not
null.
Answer =
Answer =
Answer =
(i)
drop table = it delete table or relation from database
Drop database = it delete the database from MYSQL server.
(ii)
drop table = it delete table or relation from database
DROP clause of ALTER TABLE = it delete a particular column or filed from table or relation.
Q16. Mr. Mittal is using a table with following columns:
He wrote the following command, which did not give the desired result.
Help Mr. Mittal to run the query by removing the error and write correct query.
Answer =
Doc_name
Avinash
Hariharan
Vinayak
Deepak
Sanjeev
Answer =
(a)
Doc_name
Sanjeev
(b)
Doc_name
Deepak
Sanjeev
Help Sarthak to run the query by removing the errors from the query and write the
correct query.
Answer =
Answer =
Delete is used to remove the rows, while drop is used to remove the tables and DB. delete -
removes the rows from the table - where clause can be used to delete specific rows.