Question

Write the SQL code that will create only the table structure for a table named EMP_1....

Write the SQL code that will create only the table structure for a table named EMP_1. This table will be a subset of the EMPLOYEE table. The basic EMP_1 table structure is summarized in the following table. Use EMP_NUM as the primary key. Note that the JOB_CODE is the FK to JOB so be certain to enforce referential integrity. Your code should also prevent null entries in EMP_LNAME and EMP_FNAME.

Homework Answers

Answer #1

Required SQL code is:-

CREATE TABLE EMP_1

AS (SELECT EMP_LNAME VARCHAR(200) NOT NULL,

EMP_FNAME VARCHAR(200) NOT NULL,

EMP_NUM INT NOT NULL ,

CONSTRAINT PK_EMP_1 PRIMARY KEY (EMP_NUM)

FROM EMPLOYEE);

Referential integrity for the FK to JOB table:-

**Assuming that the JOB_CODE is a primary key for EMPLOYEE table as we need a primary key for referential integrity

CREATE TABLE JOB

( TempID int NOT NULL, Name nvarchar(50) ,

CONSTRAINT PK_EMPLOYEE PRIMARY KEY NONCLUSTERED (JOB_CODE) ,

CONSTRAINT FK_EMPLOYEE_ORDER FOREIGN KEY (JOB_CODE)

REFERENCES EMPLOYEE(JOB_CODE)

ON DELETE CASCADE

ON UPDATE CASCADE ) ;

** The ON DELETE AND ON UPDATE CASCADE command is used to ensure that the changes made in employee table are also accessed in JOB table automatically.

Know the answer?
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
Similar Questions
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects....
Summary The Ch08_ConstructCo database stores data for a consulting company that tracks all charges to projects. The charges are based on the hours each employee works on each project. The structure and contents of the Ch08_ConstructCo database are shown in Figure P8.1. Use this database to answer the following problems. Database Schema The schema for the Ch08_ConstructCo database is shown below and should be used to answer the next several problems. Click this image to view it in its own...
If you had to create a new table in your database called EMPLOYEE and load data...
If you had to create a new table in your database called EMPLOYEE and load data into it using SQL commands below. CREATE TABLE EMPLOYEE (               EMP_ID INT PRIMARY KEY,               EMP_FNAME VARCHAR(200) NOT NULL,               EMP_LNAME VARCHAR(200) NOT NULL,               EMP_CITY VARCHAR(500) NULL ,               EMP_STATE VARCHAR(20) NULL ) INSERT INTO EMPLOYEE VALUE (1, ‘Kevin’, ‘Lailnay’, NULL, ‘PA’) INSERT INTO EMPLOYEE VALUE (2, ‘Sarita, ‘Kawn, ‘Princeton’,’NJ’) INSERT INTO EMPLOYEE VALUE (2, ‘Gloria, ‘Pitts, ‘Allentown, ‘PA’) INSERT INTO EMPLOYEE...
Here are SQL declarations for three tables R, S, and T: CREATE TABLE R(e INT PRIMARY...
Here are SQL declarations for three tables R, S, and T: CREATE TABLE R(e INT PRIMARY KEY, f INT); CREATE TABLE S(c INT PRIMARY KEY, d INT REFERENCES R(e) ON DELETE CASCADE); CREATE TABLE T(a INT PRIMARY KEY, b INT REFERENCES S(c) ON DELETE CASCADE); Suppose R(e,f) contains tuples (1,0), (2,4), (3,5), (4,3), and (5,7). Suppose S(c,d) contains tuples (1,5), (2,2), (3,3), (4,5), and (5,4). Suppose T(a,b) contains tuples (0,2), (1,2), (2,3), (3,4), and (4,4). As a result of the...
Perform SQL queries in the given data structure. write an SQL query that gives the number...
Perform SQL queries in the given data structure. write an SQL query that gives the number of courses taken for every student in the student table. For each instructor, show the instructor name and the number of sections that have been taught by that instructor. You do not need to include instructors who have never taught a section. List in order of decreasing the number of sections taught. Give the number of semester/year combinations in which sections have been offered....
Write the SQL statements for creating a table Event with primary key e_id, and an event...
Write the SQL statements for creating a table Event with primary key e_id, and an event date, e_date that cannot be null. Also write the statements to create a table Participant with primary key p_id, a name that can be up to 30 characters long but may be shorter, and an event e_id as a foreign key that references the corresponding event.
This is my code, but when I try to create my "Qualified" Table it won't let...
This is my code, but when I try to create my "Qualified" Table it won't let me enter foreign keys and I don't know why. CREATE TABLE STUDENT(StudentID integer, StudentName char(25) NOT NULL, primary key(StudentName)) CREATE TABLE FACULTY(FacultyID integer, FacultyName char(25) NOT NULL, primary key(FacultyID)) CREATE TABLE COURSE(CourseID integer, CourseName char(15) NOT NULL, primary key(CourseID)) CREATE TABLE QUALIFIED(DateQualified date, foreign key(FacultyID) references FACULTY(FacultyID), foreign key(CourseID) references COURSE(CourseID))
Write a script to create the following tables with attributes as specified(SQL) Customer table with Customer’s...
Write a script to create the following tables with attributes as specified(SQL) Customer table with Customer’s id, name, address, city as varchar, customer’s date of birth as date type and zip code number where the customers id is the primary key in the table, name and date of birth are mandatory. Id has a 10-character limit, name, address and city have a 50-character limit, zip has a 5-character limit Product Table with Product id, description and finish as varchar, price...
Create a paid invoices table that has the same structure as the invoices table, but it...
Create a paid invoices table that has the same structure as the invoices table, but it does not need any foreign key constraints (or other constraints, for that matter) since data will be transferred into the paid table in order to archive them out of the normal invoices table. Invoices table: create table invoices ( invoice_id number(10), vendor_id number(10) not null, invoice_number varchar2(50) not null, invoice_date date not null, invoice_total number(9,2) not null, payment_total number(9,2) default 0, credit_total number(9,2) default...
1) Add to a relational table DEPARTMENT information about the total number of employees in each...
1) Add to a relational table DEPARTMENT information about the total number of employees in each department. Note, that if a department has not employee then for such a department the total number of employees must be set to zero (0). The total number of employees must be a positive number no more than 999. Use SELECT statement to list the contents of an extended relational table DEPARTMENT in the descending order of the total number of employees. Finally, remove...
With this code: CREATE TABLE STUDENT( StudentID integer, primary key StudentName char(25) NOT NULL) I am...
With this code: CREATE TABLE STUDENT( StudentID integer, primary key StudentName char(25) NOT NULL) I am getting the 1064 error about char(25) but don't know how to fix it in MySQL workbench.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT