Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 .Describe a specific scenario, situation, or application where using a foreign

ID: 3549205 • Letter: 1

Question

1 .Describe a specific scenario, situation, or application where using a foreign key would be necessary.




2. Explain your reasons, including the characteristics of the data, that necessitate the foreign key.




3. Explain an application requirement that would necessitate the use of a view.




4. Suggest three DDL and three DML commands that you believe are most important, and provide an example of their use.  




5. Explain what each DDL and DML command does for each SQL statement that you have suggested.

Explanation / Answer

1). Foreign keys provide a relationship between two tables of data.

For example: cars & their owners.

Without a key:


Table Owners:

owner_id

owner_name


Table Cars:

car_id

car_name


There is no way to tell which car belongs to which owner. Adding a foreign key to the cars table:


cars table:

car_id

car_name

owner_id


2). Answer to this is covered in answer of 1 itself. Forign key in table car wold help in identification of its owner.


3). Views can be used as a security applications


A view can select certain columns and/or rows from a table,

and permissions set on the view instead of the underlying tables.

This allows surfacing only the data that a user needs to see.


4). DDL commands: CREATE, ALTER, DROP (most important according to me)

DML commands: UPDATE, SELECT, INSERT (most important according to me)

Examples:-

$sql = "CREATE TABLE Persons

(

PID INT NOT NULL AUTO_INCREMENT,

PRIMARY KEY(PID),

FirstName CHAR(15),

LastName CHAR(15),

Age INT

)";

The above DDL command creates a table names persons.


$sql = SELECT * from Persons

THe above example selects all entries from table Persons


5). Answer to this is present in 4th answer itself.