ZY Labs Flashcards

(28 cards)

1
Q

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.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The Movie table has the following columns:

Write a SELECT statement to select the year and the total number of movies for that year.

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
San Francisco, CA 94110
USA

How many attributes are present in the address fragment?

A
  1. City: San Francisco
  2. State and ZIP Code: CA 94110
  3. Country: USA
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why wouldn’t DATE be the correct data type to store ‘2022-01-10 14:22:12’ without losing information?

A

This is incorrect because the DATE data type only stores the date part, not the time.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why is DATETIME the correct data type to store ‘2022-01-10 14:22:12’ without losing information?

A

This is correct because the DATETIME data type stores both date and time components, preserving all the information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why wouldn’t DECIMAL be the correct data type to store ‘2022-01-10 14:22:12’ without losing information?

A

This is incorrect because DECIMAL is a numerical data type used for precise fixed-point or floating-point number storage, not temporal values.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why wouldn’t BIGINT be the correct data type to store ‘2022-01-10 14:22:12’ without losing information?

A

This is incorrect because BIGINT is a large integer data type and does not store date or time information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the common DDL commands?

A

CREATE, DROP, ALTER, TRUNCATE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the common DML commands?

A

INSERT, UPDATE, DELETE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the common DCL commands?

A

GRANT, REVOKE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the common TCL commands?

A

COMMIT, ROLLBACK, SAVEPOINT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the common DQL command?

A

SELECT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Why wouldn’t ‘Weight’ be considered the primary key for the Package table?

A

This is incorrect because weight is not unique for each package; multiple packages can have the same weight.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why wouldn’t ‘Description’ be considered the primary key for the Package table?

A

This is incorrect because a description is an optional field and may not be unique or present for every package.

17
Q

Why wouldn’t ‘LastChangedDate’ be considered the primary key for the Package table?

A

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.

18
Q

Why is ‘TrackingNumber’ considered the primary key for the Package table?

A

This is correct because tracking numbers are unique identifiers assigned to each package, ensuring that each record in the table is uniquely identifiable.

19
Q

Where would you start first.

Write a SQL statement to create the Member table.

20
Q

Where would you start first.

A
  1. Unique RatingCode values: This means you need to group the movies by their RatingCode and avoid duplicates.
  2. Count the number of movies: For each RatingCode, count how many movies have that rating.
  3. Sort by RatingCode: Arrange the results in ascending order (A–Z) based on the RatingCode.
  4. Column order: The output must have RatingCode first, followed by RatingCodeCount.
21
Q

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.

A

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);
22
Q

Display the following code result

  1. A new column must be added to the Movie table:
  2. Write a SQL statement to add the Score column to the Movie table
A
ALTER TABLE Movie
ADD Score DECIMAL(3,1);
23
Q

Where would you start first.

  1. The database contains a table named Movie.
  2. Write a SQL query to return all data from the Movie table without directly referencing any column names.
A
  • 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.
24
Q

Display the following code result

Write a SQL query to display all Title values in alphabetical order A–Z.

25
# List the objective and SQL structure Update the Year value to be 2022 for all movies with a Year value of 2020. ## Footnote How do you specify the column to update and the new value in an `UPDATE` clause?
1. Objective: Update the Year column for all movies where the Year is currently 2020 and change it to 2022. 2. SQL Statement Required: You need to write an `UPDATE` statement in SQL to modify the Year column for specific rows in the Movie table. ## Footnote The `SET` clause specifies the column to update and the new value.
26
Display the basic structure for the [SQL update](https://app.milanote.com/1UeQdo1ina668q?p=N4oXWlErVzz) statement:
``` UPDATE table_name SET column_name = new_value WHERE condition; ```
27
# Display the following code result Write a SQL statement to create the Member table.
28
# List the objectives to do the following: Write a SQL statement to delete the row with the ID value of 3 from the Movie table. ## Footnote If we were to omit the `WHERE` clause would could possibly be the result?
1. Since `ID` is the primary key, this ensures that only one row will be deleted (the one with ID = 3). 2. The `DELETE` statement is used to remove rows from a table, and the `WHERE` clause is used to specify which row(s) to delete. ## Footnote If this condition is omitted, all rows in the table would be deleted