CHECK POINT ANSWERS
CH – 7 MYSQL SQL REVISION TOUR
1. What is SQL? What are the different categories of SQL commands?
SQL i.e. Structured Query Language is a language that enables you to create and operate on relational
databases, which are sets of related information stored in tables. SQL is the set of commands that is
recognized by nearly all RDBMSs.
The different categories of SQL commands are:
a. Data Definition Language (DDL) Commands: These commands allow you to perform tasks related to
data definition e.g. creating, altering, dropping, etc.
b. Data Manipulation Language (DML) Commands: These commands allow you to perform tasks
related to data manipulation e.g. retrieval, insertion, deletion and modification.
c. Transaction Control Language (TCL) Commands: These commands allow you to manage and control
the transactions e.g. making permanent changes to database, undoing changes to database, etc.
2. What is a datatype? Name some datatypes available in MySQL.
Datatypes are means to identify the type of data and associated operations for handling it. A value’s
datatype associates a fixed set of properties with the value. Some commonly used datatypes available
in MySQL are – CHAR, VARCHAR, INT, FLOAT, etc.
3. How would you calculate 13 * 15 in SQL?
mysql> 13 * 15;
4. Is NULL value the same as 0 (zero)? Write the reason for your answer.
No, NULL value is not the same as 0 (zero). As ‘0’ is also considered as a value. But, NULL states that
that for the particular cell there in no value entered stating is to be NULL.
5. Write the UPDATE command to increase the commission (Column name: COMM) by 500 of all the
Salesmen who have achieved Sales (Column name: SALES) more than 200000. The table’s name is
COMPANY.
mysql> UPDATE COMPANY
SET COMMISSION = COMMISSION + 500
WHERE SALES > 200000;
6. While using SQL pattern matching, what is the difference between ‘_’ (underscore) and ‘%’ wildcard
symbols?
The percent (%) wildcard is used to match any substring, whereas the underscore (_) wildcard match
any character.
7. Write one similarity and one difference between CHAR and VARCHAR datatypes.
The similarity between CHAR and VARCHAR is that both allow alphabets as characters.
The difference between CHAR and VARCHAR is that of fixed length and variable length. The CHAR
datatype specifies a fixed length character string.
8. Write SQL statement to display: “Today, the date is <current date>”.
SELECT curdate( ) as ‘Today, the date is ’;
9. Write a command to add a NOT NULL constraint on FEES column of a student table.
mysql> ALTER TABLE student
CHANGE FEES FEES INT NOT NULL;
10. What is a constraint? Name some constraints that you can apply to enhance database integrity.
A constraint is a condition or check applicable on a field or set of fields. Some constraints that you can
apply to enhance database integrity are NOT NULL, DEFAULT, UNIQUE, CHECK, etc.
11. What is primary key? What is PRIMARY KEY constraint?
Primary key is a column used to uniquely identify tuples. The PRIMARY KEY constraint is used to specify
the column as a unique one to identify the tuples.
12. What is NOT NULL constraint? What is DEFAULT constraint?
A NOT NULL constraint ensures that a column cannot have NULL value. A DEFAULT constraint provides
a default value for a column when none is specified.
13. When a column’s value is skipped in an INSERT command, which value is inserted in the database?
If a column’s value is skipped in an INSERT command, the default value is inserted, if defined, otherwise
NULL value.
14. Write MySQL command to display the list of existing databases.
mysql> SHOW DATABASES;
15. Write MySQL command which will be used to open an already existing database “CONTACTS”.
mysql> USE CONTACTS;