Question

Suppose you are given the table: EMPLOYEE_DEPARTMENT (EmployeeNumber, EmployeeLastName, EmployeeFirstName, Email, DepartmentName, BudgetCode) You want to...

Suppose you are given the table:

EMPLOYEE_DEPARTMENT (EmployeeNumber, EmployeeLastName, EmployeeFirstName, Email, DepartmentName, BudgetCode)

You want to create an updated database and normalize the table

into the two tables:

DEPARTMENT (DepartmentName, BudgetCode)

EMPLOYEE (EmployeeNumber, EmployeeLastName, EmployeeFirstName, Email, DepartmentName)

Show SQL statements for creating DEPARTMENT and EMPLOYEE.

Show SQL filling the EMPLOYEE and DEPARTMENT tables with data from EMPLOYEE_DEPARTMENT.

Homework Answers

Answer #1

creating DEPARTMENT and EMPLOYEE

/*Create DEPARTMENT with DepartmentName as primary key and use it as foreign key in EMPLOYEE to link the two tables*/

CREATE TABLE DEPARTMENT (

DepartmentName varchar(255),

BudgetCode varchar(255),

PRIMARY KEY (DepartmentName)

);

CREATE TABLE EMPLOYEE (

EmployeeNumber int,

EmployeeLastName varchar(255),

EmployeeFirstName varchar(255),

Email varchar(255),

DepartmentName varchar(255),

FOREIGN KEY (DepartmentName) REFERENCES DEPARTMENT(DepartmentName)

);

filling the EMPLOYEE and DEPARTMENT tables -

INSERT INTO DEPARTMENT (DepartmentName, BudgetCode)
SELECT DepartmentName, BudgetCode FROM EMPLOYEE_DEPARTMENT ;

INSERT INTO EMPLOYEE (EmployeeNumber, EmployeeLastName, EmployeeFirstName, Email, DepartmentName)
SELECT EmployeeNumber, EmployeeLastName, EmployeeFirstName, Email, DepartmentName FROM EMPLOYEE_DEPARTMENT ;

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
Refer to Critical Thinking Assignment – Option 2 in Module 2. Your tasks begin by generating...
Refer to Critical Thinking Assignment – Option 2 in Module 2. Your tasks begin by generating and executing the SQL statements to create the Sales and Purchased Items tables. Next, you will develop and execute the SQL statements to populate the 2 database tables from the data in their respective tables in the Critical Thinking Assignment. Finally, you will write and execute queries to display all attributes (columns) and tuples (rows) in the 2 database tables. Important reminder, refer to...
Purpose: The purpose of this assignment is to provide an opportunity for you to write SQL...
Purpose: The purpose of this assignment is to provide an opportunity for you to write SQL statements to create tables and insert data into tables. Skills: Learn and practice the techniques of writing SQL statements using SQL Server Management Studio(SSMS).   Knowledge: By doing this assignment you will learn to use SSMS and write SQL statements to create new tables and insert data into the tables. Tasks: Use the following figure for the tasks below: [15 points] Write SQL statements to...
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...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL...
EMPLOYEE Field Name EMP_ID EMP_LNAME EMP_MI EMP_FNAME EMP_SEX EMP_AGE EMP_SALARY EMP_HIREDATE DEPT_CODE Table: DEPARTMENT DEPT_CODE BIOL CPTR HIST MATH RELB Data Type Text Text Text Text Text Number Currency Date/Time Text DEPT_TITLE Biology Computer Science History Mathematics Religion    Field Name DEPT_CODE DEPT_TITLE Data Type Text Text INSTRUCTIONS Use SQL commands to create the tables and enter the data shown above using MS Access. Write the following SQL statement given below: 1. 2. 3. 4. 5. 6. 7. 8. 9....
Assignment 2 Instructions You need to access to the database and write SQL queries on the...
Assignment 2 Instructions You need to access to the database and write SQL queries on the following site: https://www.w3schools.com/sql/trysql.asp?filename=trysql_op_in 1. Use INNER JOIN to create a report. In this report, list each customer’s CustomerID, CustomerName, and their each OrderID and each order’s OrderDate, if the customer has ever placed an order. You should use the Customers table and the Orders table in the database to complete this query.   2. Use INNER JOIN to create a report. In this report, list...
Question 2 (5 Marks) What can you say about the relationships between Courses and Subject, and...
Question 2 What can you say about the relationships between Courses and Subject, and Courses and Students? Will there be any problems in creating a Relational Database from your ER diagram? If there is, then describe how you will address this and re-draw the ER diagram. Question 3 Create the DDL statements to create the tables described in your modifies ER diagram in Question 2. Question 4 In your Database you created in Question 3, assume there is a student...
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table....
Lab 5 Queries with Multiple Tables In this lab, we do queries more than one table. SQL provides two different techniques for querying data from multiple tables: • The SQL subquery • The SQL join As you will learn, although both work with multiple tables, they are used for slightly different purposes. We used WMCRM database which is what we created in Lab 4. Here is the summary of the database schema (where schema is used in its meaning of...
Create 2 stored procedures: sp_AddNewUser and sp_AddNewRole. Use the ManyToMany script as your base table structures....
Create 2 stored procedures: sp_AddNewUser and sp_AddNewRole. Use the ManyToMany script as your base table structures. The stored procedure should accept the parameters needed to input the data for each table. NOTE: You do not need to input the UserID or RoleID. These are surrogate keys and the system automatically inserts them when you insert a row in the tables.   On execution, the stored procedure should check the database to see if the user exists, if so, return a message...
Save your select statements as a script. Place the semicolon at the end of each SQL...
Save your select statements as a script. Place the semicolon at the end of each SQL statement. Please number your select statements from 1 to 8 in your script and comment out each number. Include your name and student number as a comment at the top of your script. The name of the script has to be Assignment1_JohnSmith. Instead of JohnSmith use your First Name and Last Name. Upload your script trough Blackboard. Use SQL Developer to create the My...
-- Drop the tables if they existDROP TABLE REP CASCADE CONSTRAINTS;DROP TABLE CUSTOMER CASCADE CONSTRAINTS;DROP TABLE...
-- Drop the tables if they existDROP TABLE REP CASCADE CONSTRAINTS;DROP TABLE CUSTOMER CASCADE CONSTRAINTS;DROP TABLE ORDERS CASCADE CONSTRAINTS;DROP TABLE ITEM CASCADE CONSTRAINTS;DROP TABLE ORDER_LINE CASCADE CONSTRAINTS;-- You are to change CUSTOMER to CUSTOMERS for the Colonial database to avoid conflict with the CUSTOMER table in Tal.-- Create the tablesCREATE TABLE REP(REP_NUM CHAR(2) PRIMARY KEY,LAST_NAME CHAR(15),FIRST_NAME CHAR(15),STREET CHAR(15),CITY CHAR(15),STATE CHAR(2),POSTAL_CODE CHAR(5),COMMISSION DECIMAL(7,2),RATE DECIMAL(3,2) );CREATE TABLE CUSTOMER(CUSTOMER_NUM CHAR(3) PRIMARY KEY,CUSTOMER_NAME CHAR(35) NOT NULL,STREET CHAR(20),CITY CHAR(15),STATE CHAR(2),POSTAL_CODE CHAR(5),BALANCE DECIMAL(8,2),CREDIT_LIMIT DECIMAL(8,2),REP_NUM CHAR(2) );CREATE...