Question

In: Computer Science

1. write SQL statements to create the following two tables: a) Department table that contains the...

1. write SQL statements to create the following two tables:

a) Department table that contains the following columns(dept_no,deptname,location) set the deptno to be the primary key.
b) Employee table contains the following columns(emp_no,empname,deptno,salary)set the emp_no to be the primary key and dept_no to be the foreign key.

2. Write SQL statements to Insert the following 3 rows in Employee table:

       (101,’Sami’,’D-101’,5000)
       (102,’Yousef’,’D-101’,4000)
       (103,’Sami’,’D-102’,7000)

3. Write SQL statements to Insert the following 3 rows in Department table:
       (‘D-101’,’Marketing’,’loc1’)
       (‘D-102’,’Sales’,’loc2’)
       (‘D-103’,’Finance’,’loc3’)

4. Create a view for employee at marketing department.

Solutions

Expert Solution

1. a.)

CREATE TABLE Department(
    dept_no varchar(255) NOT NULL,
    deptname varchar(255),
    location varchar(255),
    PRIMARY KEY (dept_no ),
);

1. b.)

CREATE TABLE Employee(
    emp_no int NOT NULL,
    empname VARCHAR(255) NOT NULL,
    salary int,
    dept_no varchar(255) NOT NULL,
    PRIMARY KEY (emp_no),
    FOREIGN KEY (dept_no) REFERENCES Department(dept_no)
);

2.

INSERT INTO Employee (emp_no, empname, dept_no, salary)
VALUES (101,'Sami','D-101',5000),
       (102,'Yousef','D-101',4000),
       (103,'Sami','D-102',7000);

3.

INSERT INTO Department (dept_no, deptname, location)
VALUES ('D-101','Marketing','loc1'),
       ('D-102','Sales','loc2'),
       ('D-103','Finance','loc3');

4.

CREATE VIEW [Marketing employee] AS
SELECT Employee.empname , Employee.salary
FROM Employee inner join Department
ON Employee.dept_no = Department.dept_no
WHERE deptname = "Marketing";

To retreive/read the rows store in the above view, use the following SQL query :

SELECT * FROM [Marketing employee];

Related Solutions

1. Write CREATE TABLE statements for the following tables (foreign keys are in italic and bold)....
1. Write CREATE TABLE statements for the following tables (foreign keys are in italic and bold). Make sure you have all needed constraints and appropriate datatypes for attributes: Student (stID, stName, dateOfBirth, advID, majorName, GPA) Advisor (advID, advName, specialty) 2.  Insert several records in each table.
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in Oracle’s SQL*Plus.The information you need about the database ARE IN THE CHARTS BELOW. Each worksheet includes the following information about its associated table: ➢ Column names (for example, the jr_order table contains the orderID, customerID, orderDate, orderStatus, and orderShippedDate columns); ➢ Column data types (for example, orderID is INT, orderStatus is VARCHAR2(2), etc.); ➢ Column constraints, if any (for example, orderID in the jr_order...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns 2.Alter the tables to add the columns 3.Alter the tables to create the primary and foreign keys
Write create table statements to create tables for the Exoproduct employees computers database depicted by the...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the relational schema created in a mini case MC5 in chapter 3. Use insert into statements to insert no fewer than 2 and no more than 10 records per table.
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category,...
Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category, App, AppVersion, AppVersionReview: A Publisher table where each publisher is identified by an integer id and has a name (up to 40 characters). (1 mark) A Category table where each category has an id (integer), a name (up to 50 characters), and a parentId to identify its parent category. The parentId should be a foreign key to the Category table. (1.5 marks) An App...
Need SQL Tables Final Project should be included ER, NER, Table diagrams and SQL statements. The...
Need SQL Tables Final Project should be included ER, NER, Table diagrams and SQL statements. The final project is about developing an auction Web site. The details are as follows: BA is an online auction Web site. People can buy and sell items in this Web site. Buyers are people who like to buy items, and sellers are people who like to sell items. •Each seller can sell items. •Each item has a bidding start time, an end time, and...
Question 1: Part 1 Write SQL statements for the following queries from the ‘EMPLOYEE’ table in...
Question 1: Part 1 Write SQL statements for the following queries from the ‘EMPLOYEE’ table in the WPC Database in MySQL: Display all records from the Employee table for employees working in the “Marketing” department. Display all records from the Employee table for employees working in the “Marketing” department OR “Finance” Department. Display the Last Names of all employees such that each last name appears only once. Display all the attributes for employees whose employee number is less than 10....
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns:...
1. Write the statements to create a table named REQUIREMENTS. The table has the following columns: credits number (primary key) and degree name. 2. Write the statements to create a table named CANDIDATE with the following columns names. Pick the best column type: student_id, first name, last name, credits and graduation date. The credits column is a foreign key to the credits column in the REQUIREMENTS table. 3. Write the statement(s) to Insert 2 rows in your REQUIREMENTS table. Make...
Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table:...
Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table: Market, Region, ProductFamily, Manager (all Managers must have different % commissions, Commission is an attribute of the Manger). 2. Insert 5 records in Agent using all Managers 3. Insert 15 records in Product using  all ProductFamily 4. Insert 15 records in Customer using various Regions and Markets 5. Insert 50 records in SalesOrder using various Customers, Products, Agents Notes : ALL the Names ( Description)...
. Please write the SQL statements required to create the following relations, including appropriate versions of...
. Please write the SQL statements required to create the following relations, including appropriate versions of all primary and foreign key integrity constraints. (10 points) Books (isbn:CHAR(10), title: CHAR(20), author: CHAR(80), qty_in_stock: INTEGER, price: REAL, year_published: INTEGER) Customers (cid:INTEGER, cname: CHAR(80), address: CHAR(200)) Orders (ordernum:INTEGER, cid:INTEGER, order_date: DATE, cardnum:CHAR(16)) Orderlists (ordernum:INTEGER, isbn:CHAR(10), qty:INTEGER, ship_date:DATE)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT