Podcast
Questions and Answers
To revoke a user's ability to view data in the Customer table, which SQL statement should be used?
To revoke a user's ability to view data in the Customer table, which SQL statement should be used?
- `REMOVE User1 FROM Customer`
- `REMOVE User1 FROM Customer`
- `REMOVE SELECT ON Customer FROM User1`
- `REVOKE SELECT ON Customer FROM User1` (correct)
When designing a database, what type of key should be applied to the Employee
table to ensure that each employee is assigned to only an existing department in the Department
table?
When designing a database, what type of key should be applied to the Employee
table to ensure that each employee is assigned to only an existing department in the Department
table?
- A unique constraint
- An index
- A foreign key (correct)
- A primary key
- A data type
Which SQL statement returns the country and the number of orders for each country, but only includes countries where the total number of orders is less than 50?
Which SQL statement returns the country and the number of orders for each country, but only includes countries where the total number of orders is less than 50?
- `SELECT Country, orderID FROM Orders GROUP BY Country WHERE COUNT(orderID) < 50`
- `SELECT Country, orderID FROM Orders HAVING COUNT(orderID) < 50 GROUP BY Country`
- `SELECT COUNT (OrderID), Country FROM Orders HAVING COUNT (orderID) < 50 GROUP BY Country`
- `SELECT COUNT (OrderID), Country FROM Orders GROUP BY Country HAVING COUNT (orderID) < 50` (correct)
A table named Games
contains the review scores of video games. Which SQL query creates a view that lists game names in alphabetical order?
A table named Games
contains the review scores of video games. Which SQL query creates a view that lists game names in alphabetical order?
To delete from table Customer
the record of a customer with a CustomerID
of 12345, which SQL statement should be used?
To delete from table Customer
the record of a customer with a CustomerID
of 12345, which SQL statement should be used?
You need to remove a view named EmployeeView
from your database. Which SQL statement should you use?
You need to remove a view named EmployeeView
from your database. Which SQL statement should you use?
A table contains ProductID
and ProductCategory
. What database term describes the relationship where ProductID
determines ProductCategory
?
A table contains ProductID
and ProductCategory
. What database term describes the relationship where ProductID
determines ProductCategory
?
Which data type is most suitable for storing monetary values in a database table where financial calculations are frequently performed?
Which data type is most suitable for storing monetary values in a database table where financial calculations are frequently performed?
A database contains two tables: Chapter
and Language
. You're creating a third table, ChapterLanguage
, to establish a relationship between them. To create a composite primary key for the ChapterLanguage
table, which two columns should you select?
A database contains two tables: Chapter
and Language
. You're creating a third table, ChapterLanguage
, to establish a relationship between them. To create a composite primary key for the ChapterLanguage
table, which two columns should you select?
You execute the SQL statement: INSERT INTO Road VALUES (1234, 36)
. What is the result, given the table definiton CREATE TABLE Road (RoadID INTEGER NOT NULL, Distance INTEGER NOT NULL)
and the data RoadID 1234, Distance 22 and RoadID 1384, Distance 34
?
You execute the SQL statement: INSERT INTO Road VALUES (1234, 36)
. What is the result, given the table definiton CREATE TABLE Road (RoadID INTEGER NOT NULL, Distance INTEGER NOT NULL)
and the data RoadID 1234, Distance 22 and RoadID 1384, Distance 34
?
Flashcards
REVOKE SELECT ON
REVOKE SELECT ON
Disables a user's access to view data in a table.
Foreign key
Foreign key
Ensures an employee is assigned to only an existing department.
SQL for order counts
SQL for order counts
Returns country and order count where order count is less than 50.
SQL View creation
SQL View creation
Signup and view all the flashcards
SQL Delete Statement
SQL Delete Statement
Signup and view all the flashcards
Functionally dependent
Functionally dependent
Signup and view all the flashcards
Decimal data type
Decimal data type
Signup and view all the flashcards
PRIMARY KEY
PRIMARY KEY
Signup and view all the flashcards
Cascade delete
Cascade delete
Signup and view all the flashcards
Foreign key
Foreign key
Signup and view all the flashcards
Study Notes
- These notes cover SQL concepts and queries.
Disabling User Access
- To disable a user's access to a table, use
REVOKE SELECT ON Customer FROM User1
.
Foreign Keys
- A foreign key ensures that a value in one table exists in another, maintaining referential integrity.
- To ensure an employee can only be assigned to an existing department you apply a foreign key.
SQL Statements
- To return the country and number of orders in each country where the number of orders is less than 50:
SELECT COUNT (OrderID), Country FROM Orders GROUP BY Country HAVING COUNT (orderID) < 50
.
Database Backups
- A full database backup is a complete copy of all data.
- Transaction log backups do not back up all data in the database.
- Differential backups do not copy data changed before the last full backup.
- File or filegroup restores can restore a specific portion of the database.
Creating Views
- To create a view that returns an alphabetical list of game names from a table named Games:
CREATE VIEW MyGame AS SELECT Name FROM Games ORDER BY Name
.
Deleting Records
- To delete a customer record with CustomerID 12345:
DELETE FROM Customer WHERE CustomerID = 12345
.
Relational Database Table Structure
- Each value in a field in a relational database table does not need to be unique.
- Each row in a table should be unique.
- Each column name must be unique.
Removing Views
- The correct syntax to remove a view named
EmployeeView
isDROP VIEW EmployeeView
.
Database Relationships
- Functional dependency describes the relationship when the value of one attribute (ProductID) uniquely determines the value of another (ProductCategory).
Calculating Totals
- This calculates the total points per player on team ID 1:
SELECT PlayerID, SUM(Points)
FROM PlayerStat
WHERE TeamID = 1
GROUP BY PlayerID
Data Types
- Use Decimal data type for financial functions.
Composite Primary Keys
- To relate tables like Chapter and Language you select columns from Chapter and Language tables to create a composite primary key, you should choose
LanguageID
andChapterID
.
Inserting data
- If you execute the statement
INSERT INTO Road VALUES (1234, 36)
a new row should be added to the table.
Combining Query Results
- The
INTERSECT
keyword combines the results of two queries, returning only the rows present in both.
Creating Reports
- To display students enrolled on/after June 1, 2020, display students who graduated in 2022, and ordering by enrollment date (most recent first):
SELECT * FROM students
WHERE enrollment_date >= '2020-06-01' OR academic_status = 'Graduated' AND graduation_date >= '2020-01-01'
ORDER BY enrollment_date DESC
Join Operations
- Selecting from the
Employee
table and theDepartment
table gives an Equi-Join. - Full outer joins return all rows from both tables, including unmatched rows.
Creating Views
- SQL code to create a database view of North American Mammals:
CREATE VIEW (dbo).(NorthAmericanMammals_View)
AS SELECT a.Id, a.Name
FROM Animal a
WHERE a.Class = 'Mammal' AND a.InNorthAmerica = 1
Removing Columns
- To remove a column:
ALTER TABLE Customers DROP COLUMN SSN
.
Altering Tables
- If you receive an error message when running the query
ALTER TABLE Person ADD Prefix varchar(4) NOT NULL
, the DEFAULT keyword should be used to specify a default value.
Updating Tables
- To update your table with Harry in San Francisco returning their books:
UPDATE LoanedBooks SET Books = 0 WHERE (NAME = ‘Harry' AND City = 'San Francisco')
.
Creating Database Objects
- The proper syntax to create a database object is
CREATE TABLE Student (ID INT, Name VARCHAR (100), Age INT)
.
Database Table Data
- The answer to this involves matching the data type to the according field
- StudentName = VARCHAR
- GradeLevel = INT
- DaysAbsent = DECIMAL
Determining Movie Sample
- To determine whether Sample Movie appears only once in the Movie table you need to remove the ORDER BY clause
Calculations
- This answer involves the correct usage of SQL syntax
Creating Indexes
- The statement that creates an index is:
CREATE TABLE Employee (EmployeeID INTEGER PRIMARY KEY)
.
Calculations on Tables
- This answer is about selecting the correct syntax of what the query asks.
Finding Products
- The correct is
LIKE
Improving Search Performance
- A non-clustered index on the Category column will improve search performance.
Relationships between Tables
- A foreign key is used to ensure that each record in the Sales table has a valid associated salesperson record in the SalesPerson table.
SQL statements
- The keywords
PRIMARY KEY
andCONSTRAINT
are valid to use in aCREATE TABLE
statement
Deleting Rows
- Deleting rows in a table where the corresponding rows in the other table are automatically deleted, this is a
Cascade Delete
SQL statements
- The number of rows returned by the SQL statement is 5
Statements with Tables
- The answer involves the correct SQL statement keyword
- The correct answer is the following
DELETE FROM Volunteer WHERE GivenName==Tia
Chocolate
- The query that will retrieve
ItemName
andPrice
when chocolate appears in theItemDescription
column is:SELECT ItemName, Price FROM Products WHERE ItemDescription LIKE '%chocolate%';
SQL statement
- The correct answer is
DELETE FROM Employee WHERE Phone IS NULL
Data Manipulation
- A constraint is a feature a relational database uses to ensure that data entered into a column is valid
Table Production
- The correct answer is
UPDATE Product SET ProductCategory = 43 WHERE ProductDescription = ‘spoon’
Views
- The correct answer is
unchanged
Clustered index
- Clustered index
improves performance of queries that return large result sets
- And a clustered index
improves performance of queries that are accessed randomly
Table Transactions
- The correct answer is
No rows will be deleted from the table
More SQL
SELECT LastName, PhoneNumber, Extension
FROM Customers
WHERE Phone Number IS NOT NULL
ORDER BY LastName;
Product Number update
- You have to use UPDATE Products SET Price = Price * 1.06 WHERE ItemNumber = 1;
Stored procedure creation
- One reason to create a stored procedure is to improve performance
Database Normalisation
- You need to
exclude repeating groups
- You need to
exclude duplicate rows
Statements with SQL
- The correct DML (data manipulation language) statement is:
INSERT INTO Employee VALUES (‘Jack Smith’);
SQL statements
- The rows get organised in no
predictable order
Table Data
- The answer is NULLIF
Populating databases
- The correct answer is:
SELECT * FROM Employee
Key statements
- The statement you use to remove the
FOREIGN
key is:ALTER TABLE
Returning flights
SELECT FlightNumber FROM Flight
WHERE ArrivalTime > GETDATE()
ORDER BY ArrivalTime DESC
Keys
- You can create the table order with the statement
CREATE TABLE Order (OrderID INTEGER, OrderItemID INTEGER, PRIMARY KEY (OrderID, OrderItemID))
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.