Question

(a) When implementing a relational database schema in SQL, does it matter in which order you crea...

(a) When implementing a relational database schema in SQL, does it matter in which order you create tables? Hint: suppose that foreign keys exist.

(b) Explain the options available for enforcing a foreign key constraint when creating a foreign key, and what effects they have. What is the default option?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer A ) yes, when implementing a relational database schema in SQL, the order in which the tables are created matters. As also indicated in the hint. If a table A has a foreign_key associated with another table B, then we first need to create table B.

Read the following defiinition -

A foreign key is a key used to link two tables together. It is a field (or collection of fields) in one table that refers to the primary key in another table.

So if the Table B is missing than our table A won't find any key to refer to in table B.

Answer B)

There are on delete and on update options which can be used in conjunction with no action, cascade, set null and set default.

If we delete rows in the parent table, we can set one of the following actions:

  • ON DELETE NO ACTION: rolls back the delete action on the row in the parent table.
  • ON DELETE CASCADE: deletes the rows in the child table that is corresponding to the row deleted from the parent table.
  • ON DELETE SET NULL: sets the rows in the child table to NULL if the corresponding rows in the parent table are deleted, given that the foreign key columns must be nullable.
  • ON DELETE SET DEFAULT: sets the rows in the child table to their default values if the corresponding rows in the parent table are deleted, given that the foreign key columns must have default definitions.

Similarly for the UPDATE option -

If you update one or more rows in the parent table, you can set one of the following actions:

  • ON UPDATE NO ACTION: rolls back the update action on the row in the parent table.
  • ON UPDATE CASCADE: updates the corresponding rows in the child table when the rows in the parent table are updated.
  • ON UPDATE SET NULL: sets the rows in the child table to NULL when the corresponding row in the parent table is updated, given that the foreign key columns must be nullable.
  • ON UPDATE SET DEFAULT: sets the default values for the rows in the child table that have the corresponding rows in the parent table updated.

By default, it is set to ON DELETE NO ACTION if we don’t explicitly specify any action.

Note - please leave a comment for clarification.

Add a comment
Know the answer?
Add Answer to:
(a) When implementing a relational database schema in SQL, does it matter in which order you crea...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Questions: Assume you are creating a database for IS paint store. Suppose you have an ER diagram ...

    Questions: Assume you are creating a database for IS paint store. Suppose you have an ER diagram like the following: Please answer the following questions. Explain your answer. 1. Convert the ER diagrams to relational tables. 2. Specify primary keys and foreign keys in each table. For foreign keys, specify which primary key it references to. 3. Please create the tables in SQL for the relational tables in our ER diagrams. You also need to define primary keys and foreign...

  • 2. Queries. Consider the following schema for a relational database. The schema models which Uber drivers...

    2. Queries. Consider the following schema for a relational database. The schema models which Uber drivers drive which passengers to which destination at what time DRIVER-[did, dname, rating, car typej with key {did) PASSENGER-po, pname, email) with key pno) TRIP-did, pno, time, dest with key [did, time and foreign keys [did]CDRIVER[did pnoCPASSENGER pno]

  • The relational schema shown below is part of a student database. The primary and foreign keys are highlighted in bold.

    The relational schema shown below is part of a student database. The primary and foreign keys are highlighted in bold.Student (studNo, studName, address, mobileNo)Course (courseNo, courseName, creditHour, level) Registration (studNo, courseNo, regDate, semester, session)Project (projNo, projName, courseNo)Assignment (projNo, studNo, startDate, dueDate, hoursSpent)Write SQL queries based on the student database given above: 1. Create tables & constraints for the student database.2. Insert some data into the tables to check that the tables created are correct. No limit on how many rows you want...

  • Develop SQL code that would create the database files corresponding to your relational schema for the...

    Develop SQL code that would create the database files corresponding to your relational schema for the Mountain View Community Hospital case study created in Phase 2 of the class project. Write the SQL statements for creating the tables, specifying data types and field lengths, establishing primary keys and foreign keys, and implementing other constraints you identified. Write the SQL statements that create the indexes. This is optional. You should execute your SQL code on a DBMS (Oracle 11g or Oracle...

  • Question 3 refers to the relational database with a schema described below: The hospital database contains...

    Question 3 refers to the relational database with a schema described below: The hospital database contains information about the treatments of patients performed by the doctors. The database also contains information on the prescriptions ordered by the doctors. The schemas of relational tables, the meanings of attributes and specifications of primary, candidate, and foreign keys are given below. HOSPITAL HospitalCd Name Address Estate PostalCode EstablishedDate Hospital Code Name of the hospital Address of the hospital The estate where the hospital...

  • Answer each of the following questions. The questions are based on the following relational schema: Emp(*eid:...

    Answer each of the following questions. The questions are based on the following relational schema: Emp(*eid: integer¬, ename: string, age: integer, salary: decimal, doj: date) Works(*eid: integer, *did: integer, no_of_hours: integer) Dept(*did: integer, dname: string, budget: real, managerid: integer) a) Give an example of a foreign key constraint that involves the Dept relation. b) What are the options for enforcing this constraint when a user attempts to delete a Dept tuple? c) Define the Dept relation in SQL so that...

  • Q.1] Write SQL statements based on the tennis database schema (practice homework 5) Get all the different tow...

    Q.1] Write SQL statements based on the tennis database schema (practice homework 5) Get all the different town names from the PLAYERS table. 2. For each town, find the number of players. 3. For each team, get the team number, the number of matches that has been played 'for that team, and the total number of sets won. 4. For each team that is captained by a player resident in "Eltham", get the team number and the number of matches...

  • database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED...

    database and sql problme THE QUESTIONS 3, 4,5 and 6 REFER TO THE RELATIONAL TABLES LISTED BELOW CREATE TABLE Department ( DECIMAL(5) VARCHAR(30) CHAR(5) DATE NOT NULL NOT NULL NOT NULL * Department number /*Department name * Department manager number */ /Manager start date DNumber DName Manager MSDate CONSTRAINT Department_PK PRIMARY KEY(DNumber) CONSTRAINT Department_CK UNIQUE(DName) CREATE TABLE DeptLocation DECIMAL(5) VARCHAR(50) NOT NULL NOT NULL DNumber * Department number */ * Department location */ Address CONSTRAINT DeptLocation_PK PRIMARY KEY(DNumber, Address) CONSTRAINT...

  • The relational schema for the Academics database is as follows: DEPARTMENT(deptnum, descrip, instname, deptname, state, postcode)...

    The relational schema for the Academics database is as follows: DEPARTMENT(deptnum, descrip, instname, deptname, state, postcode) ACADEMIC(acnum, deptnum*, famname, givename, initials, title) PAPER(panum, title) AUTHOR(panum*, acnum*) FIELD(fieldnum, id, title) INTEREST(fieldnum*, acnum*, descrip) Some notes on the Academics database: ● An academic department belongs to one institution (instname) and often has many academics. An academic only works for one department. ● Research papers (PAPER) are often authored by several academics, and of course an academic often writes several papers (AUTHOR). ●...

  • QUESTION 1 What is the most common relationship within a relational database? Select the best answer...

    QUESTION 1 What is the most common relationship within a relational database? Select the best answer from the following. One-To-One relationship. o One-To-Many relationship. Many-To-Many relationship. Zero-To-Zero relationship. QUESTION 2 What is an "entity'? Select the best answer from the following. An entity, for our purposes, is the same as a table in the database. An entity represents one of the columns in an individual table. There are no entities in a relational database. Entities are only part of NoSQL...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT