Playing as a guest? to earn XP and track your progress.
๐ฌ Introduction to SQL Quiz
๐ฌ Introduction to SQL
SQL stands for:
Structured Query Language
Sequential Query Logic
Simple Query Language
Structured Question Language
SQL is the standard language for working with relational databases.
SQL is used to work with:
Relational databases
Word documents
Image files
Web browsers
SQL creates, changes and queries data stored in tables.
MySQL is a:
Spreadsheet
Programming language like Python
Free, open-source RDBMS
Operating system
MySQL is a relational database management system that uses SQL.
Are SQL keywords case sensitive?
Yes, they must be in small letters
No โ SELECT and select mean the same
Yes, they must be in capitals
Only on Windows
SQL keywords are not case sensitive, though capitals are used for readability.
Which symbol ends an SQL statement in MySQL?
Full stop .
Comma ,
Colon :
Semicolon ;
Each SQL statement ends with a semicolon.
DDL stands for:
Database Design Logic
Data Deletion Language
Data Definition Language
Data Display Language
DDL commands define or change the structure of database objects.
DML stands for:
Data Manipulation Language
Data Management Logic
Database Modification List
Data Making Language
DML commands work on the data stored in tables.
DQL stands for:
Data Queue List
Data Quality Language
Data Query Language
Database Quick Logic
DQL commands read (query) data โ mainly SELECT.
Which of these is a DDL command?
UPDATE
SELECT
INSERT
CREATE
CREATE, ALTER and DROP are DDL commands.
Which of these is a DML command?
ALTER
INSERT
CREATE
DROP
INSERT, UPDATE and DELETE are DML commands.
SELECT belongs to which category?
DQL
DDL
DML only as UPDATE
None of these
SELECT only reads data, so it is the DQL command.
Which group contains ONLY DDL commands?
CREATE, INSERT, SELECT
INSERT, UPDATE, DELETE
ALTER, UPDATE, DROP
CREATE, ALTER, DROP
DDL commands change the structure, not the data.
Which group contains ONLY DML commands?
SELECT, CREATE, DELETE
CREATE, ALTER, DROP
INSERT, UPDATE, DELETE
ALTER, INSERT, DROP
DML = Insert, Update, Delete (IUD).
ALTER TABLE is which type of command?
DML
DQL
DDL
None of these
ALTER changes the structure of a table.
Which data type stores FIXED-length text?
CHAR(n)
INT
VARCHAR(n)
DATE
CHAR(n) always uses n characters, padding with spaces.
Which data type stores VARIABLE-length text?
FLOAT
VARCHAR(n)
INT
CHAR(n)
VARCHAR(n) uses only as much space as the text needs, up to n.
'Riya' is stored in CHAR(10). How many characters of space does it use?
4
14
10
5
CHAR always uses the full fixed length.
'Riya' is stored in VARCHAR(10). How much space does the text use?
20 characters
4 characters (plus a tiny length marker)
1 character
10 characters
VARCHAR stores only the actual characters.
Which data type is best for a Gender column holding 'M' or 'F'?
VARCHAR(50)
CHAR(1)
DATE
FLOAT
The value always has exactly 1 character.
Which data type is best for storing whole numbers like RollNo?
DATE
VARCHAR
CHAR
INT
INT stores integers.
DECIMAL(8, 2) can store numbers with:
8 digits before the point and 2 after
Only whole numbers
2 digits in all
8 digits in all, 2 of them after the decimal point
In DECIMAL(p, s), p is the total digits and s is the digits after the point.
In which format is a DATE value written in MySQL?
'YYYY-MM-DD'
YYYYMMDD without quotes
'MM/DD/YYYY'
'DD-MM-YYYY'
Example: '2009-05-21'.
Which values must be written inside single quotes in SQL?
NULL
Numbers only
Text and dates
Column names
Text and dates go in quotes; numbers and NULL do not.
Rules applied on columns to keep the data valid are called:
Constraints
Domains
Clauses
Queries
Constraints restrict what values can be stored.
Which constraint makes sure a column cannot be left empty?
UNIQUE
NOT NULL
CHECK EMPTY
DEFAULT
NOT NULL means a value must always be given.
Which constraint makes sure no two rows have the same value in a column, but allows NULL?
NOT NULL
DEFAULT
PRIMARY KEY
UNIQUE
UNIQUE prevents duplicates; PRIMARY KEY also prevents NULL.
PRIMARY KEY is a combination of:
UNIQUE + DEFAULT
UNIQUE + NULL allowed
UNIQUE + NOT NULL
NOT NULL + DEFAULT
A primary key value must be unique and cannot be NULL.
How many PRIMARY KEY constraints can a table have?
Any number
One per column
Two
Only one
A table has only one primary key.
Which constraint gives a column a value automatically when none is given?
NOT NULL
UNIQUE
DEFAULT
PRIMARY KEY
Example: City VARCHAR(20) DEFAULT 'Kolkata'.
Which command creates a new database named SCHOOL?
MAKE DATABASE SCHOOL;
CREATE SCHOOL DATABASE;
CREATE DATABASE SCHOOL;
NEW DATABASE SCHOOL;
CREATE DATABASE name; creates a database.
Which command lists all databases?
SELECT DATABASES;
DISPLAY DATABASES;
SHOW DATABASES;
LIST DATABASES;
SHOW DATABASES shows every database on the server.
Which command opens (selects) the database SCHOOL for use?
OPEN SCHOOL;
USE SCHOOL;
GO SCHOOL;
SELECT SCHOOL;
USE makes a database the current one.
Which command deletes the whole database SCHOOL?
REMOVE DATABASE SCHOOL;
DROP DATABASE SCHOOL;
ALTER DATABASE SCHOOL;
DELETE DATABASE SCHOOL;
DROP DATABASE removes the database and all its tables.
Which command lists all the tables in the current database?
SHOW DATABASES;
SHOW TABLES;
DESCRIBE TABLES;
LIST TABLES;
SHOW TABLES lists the tables of the database in use.
Which command shows the STRUCTURE (columns and types) of table STUDENT?
SHOW STUDENT;
SELECT STRUCTURE STUDENT;
DESCRIBE STUDENT;
VIEW STUDENT;
DESCRIBE (or DESC) shows each column's name, type and constraints.
Which is the correct CREATE TABLE statement?
CREATE TABLE Item ItemNo INT, IName VARCHAR(20);
CREATE Item TABLE (ItemNo INT, IName VARCHAR(20));
CREATE TABLE Item (ItemNo INT PRIMARY KEY, IName VARCHAR(20));
CREATE TABLE Item (ItemNo INT; IName VARCHAR(20));
Columns go inside brackets, separated by commas, each with a data type.
In CREATE TABLE, column definitions are separated by:
Semicolons
Full stops
Colons
Commas
Example: (RollNo INT, Name VARCHAR(20)).
Which command adds a new column Email to table STUDENT?
ALTER TABLE STUDENT ADD Email VARCHAR(30);
ALTER STUDENT ADD COLUMN;
INSERT INTO STUDENT Email VARCHAR(30);
UPDATE STUDENT ADD Email VARCHAR(30);
ALTER TABLE ... ADD adds a column.
Which command changes the data type of column Name to VARCHAR(40)?
UPDATE STUDENT SET Name VARCHAR(40);
ALTER TABLE STUDENT CHANGE TYPE Name;
ALTER TABLE STUDENT MODIFY Name VARCHAR(40);
MODIFY STUDENT Name VARCHAR(40);
ALTER TABLE ... MODIFY changes a column's definition.
Which command removes the column Phone from STUDENT?
DELETE Phone FROM STUDENT;
UPDATE STUDENT DROP Phone;
DROP Phone FROM STUDENT;
ALTER TABLE STUDENT DROP Phone;
ALTER TABLE ... DROP removes a column.
Which command makes RollNo the primary key of an existing table STUDENT?
CREATE PRIMARY KEY RollNo;
ALTER TABLE STUDENT ADD PRIMARY KEY (RollNo);
UPDATE STUDENT PRIMARY KEY (RollNo);
ALTER TABLE STUDENT SET PRIMARY KEY RollNo;
ADD PRIMARY KEY (column) adds the constraint.
Which command removes the primary key from STUDENT?
DELETE PRIMARY KEY FROM STUDENT;
ALTER TABLE STUDENT DROP PRIMARY KEY;
DROP PRIMARY KEY STUDENT;
ALTER TABLE STUDENT REMOVE KEY;
A table has only one primary key, so no column name is needed.
Which command deletes the table STUDENT completely (structure and data)?
REMOVE STUDENT;
DELETE TABLE STUDENT;
DROP TABLE STUDENT;
DELETE FROM STUDENT;
DROP TABLE removes the whole table.
Which command adds a new row to a table?
ADD ROW
ALTER TABLE
INSERT INTO
UPDATE
INSERT INTO table VALUES (...) adds a record.
Which is a correct INSERT statement?
INSERT Student VALUES (9, Neha, F);
INSERT INTO Student VALUES (9, 'Neha', 'F', 'Science', 81, 4500, 'Pune');
ADD INTO Student VALUES (9, 'Neha');
INSERT INTO Student (9, 'Neha');
Text values go in single quotes; values follow the column order.
When values are given for ALL columns, the values must be in:
Alphabetical order
Any order
The same order as the columns in the table
Reverse order
Without a column list, values must match the table's column order.
INSERT INTO Student (RollNo, Name) VALUES (10, 'Ravi'); What will the other columns contain?
The previous row's values
NULL (or their DEFAULT value)
Empty quotes
0
Columns not mentioned get NULL, or their DEFAULT value if one is set.
How do you insert several rows with ONE INSERT statement in MySQL?
Use INSERT MANY
Write ROWS = 3
It is not possible
Separate each row's values with commas: VALUES (...), (...)
VALUES (1, 'A'), (2, 'B'), (3, 'C'); inserts three rows.
Which value can be written without quotes in INSERT?
'2009-05-21'
NULL
'Kolkata'
'Riya'
NULL is a keyword and is written without quotes.
Inserting a row with a RollNo that already exists (RollNo is the PRIMARY KEY) will:
Replace the old row
Insert both rows
Insert NULL
Give a duplicate entry error
A primary key value must be unique.
Which statement about DDL and DML is TRUE?
DML deletes tables
DDL changes the data; DML changes the structure
DDL changes the structure; DML changes the data
Both only read data
CREATE/ALTER/DROP work on structure; INSERT/UPDATE/DELETE work on data.
Which is an advantage of SQL?
It needs a new language for each database
It can only read data
Its commands are short English-like words
It works only on one computer
SQL is easy to learn and is the standard language for relational databases.
Which data type is best for a column storing a student's date of birth?
CHAR(1)
INT
FLOAT
DATE
DATE stores dates in 'YYYY-MM-DD' format.
A column Price must store values like 1250.75 exactly. Which data type is best?
INT
DECIMAL(7, 2)
DATE
CHAR(7)
DECIMAL stores exact numbers with a fixed number of decimal places.