NAME: __________________________ C/ Y/ S: _______________ Score: ________
Answer the given questions for each item.
I. BASIC TABLE QUERIES
DATABASE SAMPLE
1. Write a query in SQL to find the title and year of the movies.
2. Write a query in SQL to find the year when the movie American Beauty released.
3. Write a query in SQL to find the movie which was released in the year 1999.
4. Write a query in SQL to find the movies which was released before 1998.
5. Write a query in SQL to return the name of all reviewers and name of movies together in
a single list.
6. Write a query in SQL to find the name of all reviewers who have rated 7 or more stars to
their rating.
7. Write a query in SQL to find the titles of all movies that have no ratings.
8. Write a query in SQL to find the titles of the movies with ID 905, 907, 917.
9. Write a query in SQL to find the list of all those movies with year which include the words
Boogie Nights.
10. Write a query in SQL to find the ID number for the actor whose first name is 'Woody' and
the last name is 'Allen'.
II. CREATE TABLE STATEMENT
Field Type Null Key Default Extra
COUNTRY_ID varchar (2) YES NULL
COUNTRY_NAME varchar (40) YES NULL
REGION_ID decimal YES NULL
(10,0)
1. Write a SQL statement to create a simple table countries including columns
country_id,country_name and region_id.
2. Write a SQL statement to create a simple table countries including columns
country_id,country_name and region_id which is already exists.
3. Write a SQL statement to create the structure of a table dup_countries similar to countries.
4. Write a SQL statement to create a duplicate copy of countries table including structure and
data by name dup_countries.
5. Write a SQL statement to create a table countries set a constraint NULL.
6. Write a SQL statement to create a table named jobs including columns job_id, job_title,
min_salary, max_salary and check whether the max_salary amount exceeding the upper limit
25000.
7. Write a SQL statement to create a table named countries including columns country_id,
country_name and region_id and make sure that no countries except Italy, India and China will
be entered in the table.
8. Write a SQL statement to create a table named job_histry including columns employee_id,
start_date, end_date, job_id and department_id and make sure that the value against column
end_date will be entered at the time of insertion to the format like '--/--/----'.
9. Write a SQL statement to create a table named countries including columns
country_id,country_name and region_id and make sure that no duplicate data against column
country_id will be allowed at the time of insertion.
10. Write a SQL statement to create a table named jobs including columns job_id, job_title,
min_salary and max_salary, and make sure that, the default value for job_title is blank and
min_salary is 8000 and max_salary is NULL will be entered automatically at the time of insertion
if no value assigned for the specified columns.
III. INSERT INTO STATEMENT
Structure of the table COUNTRIES
Field Type Null Key Default Extra
COUNTRY_ID varchar (2) YES NULL
COUNTRY_NAME varchar (40) YES NULL
REGION_ID decimal YES NULL
(10,0)
1. Write a SQL statement to insert a record with your own value into the table countries against
each column.
2. Write a SQL statement to insert one row into the table countries against the column
country_id and country_name.
3. Write a SQL statement to create duplicate of countries table named country_new with all
structure and data.
4. Write a SQL statement to insert NULL values against region_id column for a row of
countries table.
5. Write a SQL statement to insert 3 rows by a single insert statement.
IV. UPDATE TABLE STATEMENT
1. Write a SQL statement to change the email column of employees table with 'not available'
for all employees.
2. Write a SQL statement to change the email and commission_pct column of employees
table with 'not available' and 0.10 for all employees.
3. Write a SQL statement to change the email and commission_pct column of employees table
with 'not available' and 0.10 for those employees whose department_id is 110.
4. Write a SQL statement to change the email column of employees table with 'not available'
for those employees whose department_id is 80 and gets a commission is less than .20%
5. Write a SQL statement to change the email column of employees table with 'not available'
for those employees who belongs to the 'Accouning' department.