Question

(SQL) Write DDL statements to create the tables below and use appropriate data types for the...

(SQL)

Write DDL statements to create the tables below and use appropriate data types for the attributes.Relational database schema:

Teacher = [CourseN, Quarter,TeacherName]

Course = [CourseN,CourseName, Nunit)

LocationNTime = [CourseN, Quarter , DayTime, RoomN] . //Examples of DayTime: M2:00AM, W4:50PM, and T8:00PM. Note that DayTime is represented as a string.

Student = [studentName, CourseN, Quarter]

....................

The DDL statement must include at least the following constraints:

Every Primary Key;

Every Foreign Key;

For every Foreign Key constraint, the referential integrity constraints are:

ON DELETE SET NULL or CASCADE or DEFAULT whatever it is appropriate;

ON UPDATE SET NULL or CASCADE whatever it is appropriate;

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

SOLUTION :

Note:we need to create Course Table first since other tables are using the primary key of Course as foreign Key

SINCE I have used CourseN as part of primary key we cant use ON delete SET NULL constraint since it will throughs error, SInce if we do that it will violate the primary key

Course TABLE:

EXPLANATION:

1 CourseN is the courseNumber by which the course is identified so it is kept as primary key

2 CourseName is a string which stores the name of the course

3.Nuint is the number of units that the course has so it is number considering the unit numbers will be less than 9999 given size as 4

DDL COMMAND :

CREATE TABLE Course (CourseN VARCHAR2(20),CourseName VARCHAR2(20), Nunit NUMBER(4),
PRIMARY  KEY(CourseN))

IMAGE:

Teacher Table:

EXPLANATION:

CASCADE -> It will Update or Delete the details whenever there is a change in the related key values here we are using it with update so it will update the data.

1 CourseN is foreign attribute of the Course here i am applying the referential integrity constraints like ON UPDATE of the courseN of the primary key the data here also needs to the updated on delete of the courseN we are keep it as NULL.

2. Quarter is given as varchar2(6) Assuming that the Quarter may be in the format of "Q1" or "Q2" like this

3 The primary key is CourseN and Teacher Name assuming that the same course is not taught by another teacher of same complete name

DDL COMMAND:

CREATE TABLE Teacher (CourseN VARCHAR2(20), Quarter varchar2(6), TeacherName VARCHAR2(20),PRIMARY KEY(CourseN,TeacherName), FOREIGN KEY(CourseN) REFERENCES Course(CourseN) ON UPDATE CASCADE )
  

IMAGE

LocationN Table:

EXPLANATION:

1. Here even CourseN we have applied the same referential integrity constraints as the previous one

2. DayTime is taken as a varchar2(15) assuming that it length will not exceed 15 characters

3. Room number is assummed that it wont go beyond 4 digits and given length as 4

4 Primary key is taken as the CourseN,DayTime and RooomN considering that two same courses cant be taught at same room at same time so it is considered as a key

DDL COMMAND:

CREATE TABLE LocationNTime (CourseN VARCHAR2(20), Quarter varchar2(15),DayTime varchar2(10), RoomN number(4),PRIMARY KEY(CourseN,DayTime,RoomN),FOREIGN KEY(CourseN) REFERENCES Course(CourseN) ON UPDATE CASCADE )   

IMAGE:

Student TABLE

EXPLANATION:
1. Here primary key is assumed to be all the three attributes since in a course there can be more than 1 student with same name so we have kept three as the primary key

2. When there is any update in courseN we applied cascade so that it will update the data

DDL COMMAND:

CREATE TABLE Student (studentName VARCHAR2(20),CourseN VARCHAR2(20), Quarter varchar2(6),PRIMARY KEY( studentName,CourseN,Quarter),FOREIGN KEY(CourseN) REFERENCES Course(CourseN) ON UPDATE CASCADE )

IMAGE:

Add a comment
Know the answer?
Add Answer to:
(SQL) Write DDL statements to create the tables below and use appropriate data types for the...
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
  • 4 Consider the following relational schema, DDL statements and tables: EMPLOYEE( EmployeeID, EmployeeName, SupervisorID, DepartmentID) PROJECT...

    4 Consider the following relational schema, DDL statements and tables: EMPLOYEE( EmployeeID, EmployeeName, SupervisorID, DepartmentID) PROJECT (ProjectID, EmployeeID) DEPARTMENT( Department ID, DepartmentName) CREATE TABLE EMPLOYEE ( EmployeeID          INT           PRIMARY KEY,    EmployeeName   VARCHAR(50)      NOT NULL,    SupervisorID INT DEFAULT 9,    DepartmentID   INT,    FOREIGN KEY (SupervisorID) REFERENCES EMPLOYEE (EmployeeID)    ON DELETE SET DEFAULT   ),    FOREIGN KEY (DepartmentID) REFERENCES DEPARTMENT(DepartmentID)    ON UPDATE SET NULL); CREATE TABLE PROJECT ( ProjectID    INT          PRIMARY KEY, EmployeeID INT DEFAULT 9, FOREIGN...

  • 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...

  • Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a...

    Utilize the JigSaw SQL file below to create a Star Schema diagram. Remember, to create a Star Schema from a normalized data model, you will need to denormalize the data model into fact and dimension tables. The diagram should contain all of the facts and dimension tables necessary to integrate the JigSaw operational database into a data warehouse. Write a brief paper describing the challenges you experienced in completing this assignment. -- CREATE DATABASE js; CREATE TABLE buy_methods ( buy_code...

  • Use the SQL statements provided to create your tables. Write one SQL statement for each of...

    Use the SQL statements provided to create your tables. Write one SQL statement for each of the following problems. You can only use the conditions listed in the tasks. E.g., in task 1, you cannot manually look up pid of Information Systems undergraduate program. Here is the given code: drop table textbook_schedule cascade constraints; drop table textbook_author cascade constraints; drop table schedule cascade constraints; drop table course cascade constraints; drop table textbook cascade constraints; drop table author cascade constraints; drop...

  • SQL Query Question: I have a database with the tables below, data has also been aded...

    SQL Query Question: I have a database with the tables below, data has also been aded into these tables, I have 2 tasks: 1. Add a column to a relational table POSITIONS to store information about the total number of skills needed by each advertised position. A name of the column is up to you. Assume that no more than 9 skills are needed for each position. Next, use a single UPDATE statement to set the values in the new...

  • Sample data for these tables are shown in Figures 3-26 and 3-27. For each SQL statement...

    Sample data for these tables are shown in Figures 3-26 and 3-27. For each SQL statement you write, show the results based on these data. If possible, run the statements you write for the questions that follow in an actual DBMS, as appropriate, to obtain results. Use data types that are consistent with the DBMS you are using. If you are not using an actual DBMS, consistently represent data types by using either the MySQL, Microsoft SQL Server, or Oracle...

  • Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys...

    Learning Objectives: Learn to define constraints on tables Lean to define primary keys and foreign keys Exercise                                                                                In Lab 09, we will continue the practice of creating tables. You will need to write SQL statements for the tasks specified below. After you complete them, submit your SQL script (in one *.sql file) to Blackboard by 11:59pm Nov. 16 (Friday). Include your name as a comment in the SQL script submitted. The creation statement for each table is worth one point,...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • Using SQL and the following info Question 3: Find the people who do not have Viper...

    Using SQL and the following info Question 3: Find the people who do not have Viper Certification but are still assigned to Viper class ship Find the fname, lname, and ship_instance_id for all people who do not have Viper certification but are assigned to at least one instance of a Viper class ship (this includes all variants of Viper class ships). Return a row for every ship/person combination. Order your results by fname in ascending order. Use the BSG database...

  • 6. With respect to database systems, which of the following statement(s) is (are) true? a. The...

    6. With respect to database systems, which of the following statement(s) is (are) true? a. The physical view of data is how people conceptually organize and understand the relationships among data items. b. The DML builds the data dictionary, creates the database, describes logical views for each user, and specifies security constraints. c. A record layout shows the items stored in a file, including the type of data stored and both the order and length of the data fields. d....

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