Ch 7 CONCEPTS Flashcards

1
Q

Table A is Horse with PK ID
Table B is Student with PK ID
Table C is LessonSchedule with PKs HorseID and LessonDateTime & FK StudentID referencing Student(ID) and FK HorseID referencing Horse(ID)

If a row is deleted from A, how do we tell rows in C with the same Horse ID to be automatically deleted?

A

After the rest of the LessonSchedule table is created, in the same table creation statement, we add:

FOREIGN KEY (HorseID) REFERENCES Horse(ID) ON DELETE CASCADE,

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

Table A is Horse with PK ID
Table B is Student with PK ID
Table C is LessonSchedule with PKs HorseID and LessonDateTime & FK StudentID referencing Student(ID) and FK HorseID referencing Horse(ID)

If a row is deleted from B, how do we tell rows in C with the same Student IDs to be automatically set to NULL?

A

After the rest of the LessonSchedule table is created, in the same table creation statement, we add:

FOREIGN KEY (StudentID) REFERENCES Student(ID) ON DELETE SET NULL

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

How do you create a CHECK statement while creating a table that checks and requires the input to be one of MULTIPLE options?

A

Breed VARCHAR(20) CHECK (Breed IN (‘Egyptian Arab’, ‘Holsteiner’, ‘Quarter Horse’, ‘Paint’, ‘Saddlebred’))

You have to use the IN keyword before the list of possible optiona and also put the check statement in parenthesis AND the LIST in parenthasis inside the check.

ColName DataType CHECK (ColName IN (‘A’, ‘B’, ‘C’))

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

What is a transaction and how do you start one?

A

A transaction is a group of tasks to be executed. All tasks have to succeed in executing or else the entire transaction fails.

BEGIN TRANSACTION transaction_name ;

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

What is a save point and how do you create one?

A

In SQL, a SAVEPOINT is a mechanism that allows you to create a point within a transaction to which you can later roll back. This feature is particularly useful when you want to implement a partial rollback in case of errors or other exceptional conditions within a transaction.

START TRANSACTION;

– Perform some SQL operations

SAVEPOINT my_savepoint;

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

How do you go back to a specific save point?

A

ROLLBACK TO my_savepoint;

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