Question

In: Other

A company database needs to store information about employees (identified by ssn, with salary and phone...

A company database needs to store information about employees (identified by ssn, with salary and phone as attributes), departments (identified by dno, with dname and budget as attributes), and children of employees (with name, age, and relationship to the employee as attributes). Employees work in departments; each department is managed by an employee; a child must be identified uniquely by name when the parent (who is an employee; assume that only one parent works for the company) is known. We are not interested in information about a child once the parent leaves the company.

Please provide me SQL statements to create the corresponding relations and capture as many of the constraints as possible.

Solutions

Expert Solution

According to the problem statement the ER diagram of the database will be as follows:-

From the question it is clear that there will be 3 entities which are represented by rectangular box and each entities will have 3 attributes which are represented by the oval shape, the relationship are represented by diamond box in the ER diagram and followings are the relationship between entities:-

  • Employee works for department (N employees works for the 1 department)
  • Employee manages the department (only 1 employee manages the department)
  • Employee has the children (1 employee has one or more children)

Now we convert the above ER diagram into the database using the sql syntax as follows:-

(1.) Creating database Company :-

create database Company;

use Company;

(2.) Creating the tables :-

All the entities become the tables and the attributes become the columns of each table of the database therefore the DDL command to create table is as follows:-

create table Employee (SSN int(3) not null, Salary decimal(8,2), Phone int(10), Dnumber int(3));

create table Department (Dno int(3) not null, Dname varchar(20), Budget decimal(8,2));

create table Children (Name char(30) not null, Age int(2), Relationship char(20), ESSN int(3));

(3.) Adding primary key constraints to the table:-

Primary keys can be added to the table by using the alter command, therefore the DDL command to alter table is as follows:-

Alter table Employee add primary key (SSN);

Alter table Department add primary key (Dno);

Alter table Children add primary key (Name);

(4.) Adding foreign key constraints to the table:-

Since the relationship between tables shows different cardinalities therefore their is need to add foreign keys into the table.Foreign keys can be added to the table by using the alter command, therefore the DDL command to alter table is as follows:-

Alter table Employee add foreign key (Dnumber) references Department (Dno);

Alter table Children add foreign key (ESSN) references Employee (SSN);

(5.) Adding records into the tables:-

Recordes can be inserted using DML command as follows:-

Insert into tablename values (value1, value2, value3,....);

In this manner we can add records in any of the table.


Related Solutions

Assume you are creating a database for IS paint store. The database needs to support the...
Assume you are creating a database for IS paint store. The database needs to support the following business functions. • Allow customers to browse the inventory. Customers want to search by paint types and colors. Customers also wants to know pricing information. • A customer can be a regular customer (e.g., home owner), or a contractor or painting professionals. Different customers can get different discounts for the same type of paint. We assume each customer can get the same discount...
Consider the following database schema: Frequents(kid, store) Sells(store, candy) Likes(kid, candy) Stores(store, city, phone) Kids(kid, city,...
Consider the following database schema: Frequents(kid, store) Sells(store, candy) Likes(kid, candy) Stores(store, city, phone) Kids(kid, city, age) Write relational algebra expression(s) to: a) Find the stores in ’Warrensburg’, for each display only the store name and phone number. b) Find the stores in ’Warrensburg’, which sells ’Hersheys’ or ’Mars’. Your expression must use set union. c) Repeat the above without using set union. d) Find the kids who are 10 years or older and like ’M&Ms’. e) Find the kids...
How to generate database diagram for a database that stores information about the downloads that users...
How to generate database diagram for a database that stores information about the downloads that users make. Each user must have an email address, first name, and last name. Each user can have one or more downloads. Each download must have a filename and download date/time. Note: I want steps on how to generate this diagram using oracle SQL developer Each product can be related to one or more downloads. Each product must have a name.
Jan 1. The company haired 4 employees with a monthly salary of 1,500 each. The salary...
Jan 1. The company haired 4 employees with a monthly salary of 1,500 each. The salary is to be paid on the first day of each month. How will be recording the transaction?
Part 1Write a narrative that describes what information you will store in a database. Be as...
Part 1Write a narrative that describes what information you will store in a database. Be as descriptive as you can be. Part 2Create an E-R diagram that corresponds to yournarrative. If you have fewer than three entities in your E-R diagram, revise your narrative!Remember that foreign key values should not be in your entities.Make sure that you include maximum and minimum cardinalities for your relationships.You can use a tool to create the E-R diagram or draw it by hand and...
Chapter 15 contains information about the rights of the employees of a company as well as...
Chapter 15 contains information about the rights of the employees of a company as well as the responsibilities of the employer. A few of the concerns that employees have include the right to privacy and labor unions. Do you believe that drug testing of employees is necessary? Why and why not? Also, include at least 1 pro and 1 con of drug testing and name the occasions drug testing may be used. In addition,  explain how much privacy can employees expect...
1. A cosmetic product retailer needs to create a database to keep track of the information...
1. A cosmetic product retailer needs to create a database to keep track of the information for its business operations. The company has a web site that posts all its products. The product information includes product ID, product name, description, and unit price. The company also needs to keep track of customers’ information, including customer names, their shipping addresses, and the email address. The company creates an account for each customer for identification and tracking purpose. A customer can purchase...
Database design of cothing Online Shopping System. Schema represents minimal information required to store information of...
Database design of cothing Online Shopping System. Schema represents minimal information required to store information of a shop and products to sell. Cart information can be stored in session or if wish-list / watchlist is needed, the schema can be simply extended. Enjoy. SQL and methodology.
C++ There is a file, called EmployeeInfo.txt, that contains information about company employees work for a...
C++ There is a file, called EmployeeInfo.txt, that contains information about company employees work for a week. You will write a program that reads the info from the file, and produces an output file called EmployeePay.txt with information about the employees pay amount for that week. Details: The input file is called EmployeeInfo.txt There are 4 lines of input Each line has the same form Last Name, first Name, hours worked, pay rate, tax percentage, extra deductions Example: John Doe...
Designing and refining an Entity-Relationship Model A company wants a simple database to record information about...
Designing and refining an Entity-Relationship Model A company wants a simple database to record information about ticket sale for theatre performances. They describe the key elements of their requirements in the following points: • Customers have a name, phone number, a credit card no, and a unique customer number. • Customers can attend many performances, and each performance can have many customers attending. • Each performance of a show is on at a specific date and time, at a venue....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT