logo

Relational Data Structure, Tables, Inserts and Queries

Create a small database for ABC Company to store employee, department, project, and dependent information. Perform various actions such as identifying constraints, creating tables, inserting values, and writing queries.

25 Pages2447 Words483 Views
   

Added on  2023-06-12

About This Document

This article explains the relational data structure of Desklib's database and provides the SQL code for creating tables, inserting data, and querying the database. The tables include Department, Dept_Locations, Employee, Project, Dependent, and Works_On. The article also includes sample insert statements and queries.

Relational Data Structure, Tables, Inserts and Queries

Create a small database for ABC Company to store employee, department, project, and dependent information. Perform various actions such as identifying constraints, creating tables, inserting values, and writing queries.

   Added on 2023-06-12

ShareRelated Documents
SIT103 Database and Information Retrieval
Assignment 2
5/19/2018
Student ID:
Module Tutor:
Relational Data Structure, Tables, Inserts and Queries_1
Relational Data Structure
Table Name Primary Key Foreign Key NOT NULL Constraints
Department DNo NOT NULL
Dept_Locations DNo, Location FOREIGN KEY (DNo)
REFERENCES
Department(DNo)
NOT NULL
Employee Ssn FOREIGN KEY (DNo)
REFERENCES
Department(DNo)
NOT NULL
Project Pnumber FOREIGN KEY (DNum,
Plocation)
REFERENCES
Dept_Locations(DNo,
Location)
NOT NULL
Dependent Essn, Dependent_Name FOREIGN KEY (Essn)
REFERENCES
Employee(Ssn)
NOT NULL
Works_On Essn, Pno FOREIGN KEY (Pno)
REFERENCES
Project(Pnumber),
FOREIGN KEY (Essn)
REFERENCES
Employee(Ssn)
NOT NULL
(Easy Computer Academy 2017)
(BigennersBook 2017)
Relational Data Structure, Tables, Inserts and Queries_2
Create Tables
Department Table
CREATE TABLE Department
( DNo NUMBER NOT NULL,
DName VARCHAR2(30) NOT NULL,
Mgr_ssn Number NOT NULL,
Mgr_start_date date NOT NULL,
CONSTRAINT "DEP_PK" PRIMARY KEY (DNo)
);
Relational Data Structure, Tables, Inserts and Queries_3
Dept_Locations Table
CREATE TABLE Dept_Locations
( DNo NUMBER NOT NULL,
Location VARCHAR2(30) NOT NULL,
CONSTRAINT "DEPLOC_PK" PRIMARY KEY (DNo, Location),
CONSTRAINT fk_dept
FOREIGN KEY (DNo)
REFERENCES Department(DNo)
);
Relational Data Structure, Tables, Inserts and Queries_4
Employee Table
CREATE TABLE Employee
( Fname VARCHAR2(30) NOT NULL,
Minit VARCHAR2(1) NOT NULL,
Lname VARCHAR2(30) NOT NULL,
Ssn Number NOT NULL,
BDate Date NOT NULL ,
Address VARCHAR2(50) NOT NULL ,
Sex VARCHAR2(1) NOT NULL ,
Salary Number NOT NULL ,
Super_ssn Number NULL,
DNo Number NOT NULL,
CONSTRAINT "EMP_PK" PRIMARY KEY (Ssn),
CONSTRAINT fk_departments
FOREIGN KEY (DNo)
REFERENCES Department(DNo)
);
Relational Data Structure, Tables, Inserts and Queries_5
Project Table
CREATE TABLE Project
( Pnumber NUMBER NOT NULL,
Pname VARCHAR2(30) NOT NULL,
Plocation VARCHAR2(30) NOT NULL,
DNum NUMBER NOT NULL,
CONSTRAINT "PROJECT_PK" PRIMARY KEY (Pnumber),
CONSTRAINT fk_deptLoc
FOREIGN KEY (DNum, Plocation)
REFERENCES Dept_Locations(DNo, Location)
);
Relational Data Structure, Tables, Inserts and Queries_6

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
SIT103- Database and Information Retrieval Assignment 2 Report
|22
|2447
|193

Draft SQL Implementation Assignment
|12
|1254
|190