SQL Quiz
SQL Quiz
Write a SQL Script to Create a Database called QUIZ, Size 5mb on C:\CCTB111, Maxsize
7mb and Log File 4mb. Should the Log and Data Files be on the same drive? Why?
LOG ON
(NAME = MyDatabase_Log,
FILENAME = 'D:\CCTB111\MYCCTB111.LDF',
SIZE = 2MB,
MAXSIZE = 5MB)
● The LDF file should be on a separate drive / location as it can be used to recover a
corrupt MDF file.
4. What are Primary Key, Foreign Key and Index? Why would you use index in a database?
● Primary Key is a column in a table that accepts unique values for each row
● A Foreign Key is a Primary Key referenced from another table
● An Index is a lookup table that is used to speed up database searching
6. What is a Subquery? Write a Subquery that displays Students Info (StudentID, CourseID and
Marks) of Students with Marks below the Class Average Mark:
7. What is an Aggregate Query? Name 4 Aggregate Functions and a very brief description
● An aggregate query takes data from a column and provides a result from it based on the
data
○ Avarage = avg()
○ Maximum value = max()
○ Minimum value = min()
○ Number of records count()
8. What SQL Statements do you use to Populate Tables, Delete Rows, and Update Rows?
● A View is a “Virtual Table”, which is sort of a copy of an actual table that can be viewed
and altered by specific people with specific security permissions
10. What is a Calculated Field? Provide 2 SQL formulas for calculating the AGE?
11. Describe Wildcard Characters in SQL. What Operator should they be used with?
● * means “all”
○ Used in SELECT
● % means “any number of characters after this character”
○ Used in LIKE
● _ means “any single character”
○ Used in LIKE