ZY Labs Flashcards
(28 cards)
The Horse table has the following columns:
ID - integer, primary key
RegisteredName - variable-length string
Breed - variable-length string
Height - decimal number
BirthDate - date
Write a SELECT
statement to select the registered name and height for only horses that have an above average height. Order the results by height (ascending).
Hint: Use a subquery to find the average height.
The database has three tables for tracking horse-riding lessons:
Write a SELECT
statement to create a lesson schedule for Feb 1, 2020 with the lesson date/time, student’s first and last names, and the horse’s registered name. Order the results in ascending order by lesson date/time, then by the horse’s registered name. Make sure unassigned lesson times (student ID is NULL) appear in the results.
Write a SELECT
statement to create a lesson schedule with the lesson date/time, horse ID, and the student’s first and last names. Order the results in ascending order by lesson date/time, then by horse ID. Unassigned lesson times (student ID is NULL
) should not appear in the schedule.
Hint: Perform a join on the Student and LessonSchedule tables, matching the student IDs.
The Movie table has the following columns:
Write a SELECT
statement to select the year and the total number of movies for that year.
San Francisco, CA 94110 USA
How many attributes are present in the address fragment?
- City: San Francisco
- State and ZIP Code: CA 94110
- Country: USA
Why wouldn’t DATE be the correct data type to store ‘2022-01-10 14:22:12’ without losing information?
This is incorrect because the DATE
data type only stores the date part, not the time.
Why is DATETIME the correct data type to store ‘2022-01-10 14:22:12’ without losing information?
This is correct because the DATETIME
data type stores both date and time components, preserving all the information.
Why wouldn’t DECIMAL be the correct data type to store ‘2022-01-10 14:22:12’ without losing information?
This is incorrect because DECIMAL
is a numerical data type used for precise fixed-point or floating-point number storage, not temporal values.
Why wouldn’t BIGINT be the correct data type to store ‘2022-01-10 14:22:12’ without losing information?
This is incorrect because BIGINT
is a large integer data type and does not store date or time information.
What are the common DDL commands?
CREATE, DROP, ALTER, TRUNCATE
What are the common DML commands?
INSERT, UPDATE, DELETE
What are the common DCL commands?
GRANT, REVOKE
What are the common TCL commands?
COMMIT, ROLLBACK, SAVEPOINT
What is the common DQL command?
SELECT
Why wouldn’t ‘Weight’ be considered the primary key for the Package table?
This is incorrect because weight is not unique for each package; multiple packages can have the same weight.
Why wouldn’t ‘Description’ be considered the primary key for the Package table?
This is incorrect because a description is an optional field and may not be unique or present for every package.
Why wouldn’t ‘LastChangedDate’ be considered the primary key for the Package table?
This is incorrect because the date a package was last changed is not unique to each package and could be the same for several packages.
Why is ‘TrackingNumber’ considered the primary key for the Package table?
This is correct because tracking numbers are unique identifiers assigned to each package, ensuring that each record in the table is uniquely identifiable.
Where would you start first.
Write a SQL statement to create the Member table.
Where would you start first.
- Unique RatingCode values: This means you need to group the movies by their RatingCode and avoid duplicates.
- Count the number of movies: For each RatingCode, count how many movies have that rating.
- Sort by RatingCode: Arrange the results in ascending order (A–Z) based on the RatingCode.
- Column order: The output must have RatingCode first, followed by RatingCodeCount.
Where would you start first.
- A new column must be added to the Movie table:
- Column name:
Score
- Data type:
decimal(3,1)
Write a SQL statement to add the Score column to the Movie table.
To add a new column to an existing table in SQL, you can use the ALTER TABLE
statement followed by an ADD
clause. You need to specify the table name, the new column name, and its data type.
ALTER TABLE Movie ADD Score DECIMAL(3,1);
Display the following code result
- A new column must be added to the Movie table:
- Write a SQL statement to add the Score column to the Movie table
ALTER TABLE Movie ADD Score DECIMAL(3,1);
Where would you start first.
- The database contains a table named Movie.
- Write a SQL query to return all data from the Movie table without directly referencing any column names.
- The SQL query
SELECT * FROM Movie
; accomplishes this by using the*
wildcard to select all columns implicitly. - This approach is efficient and adheres to the constraint of not directly referencing any column names.
Display the following code result
Write a SQL query to display all Title values in alphabetical order A–Z.