0% found this document useful (0 votes)
71 views2 pages

COMPANY DATABASE - Create Table

The document outlines the steps to connect to a PostgreSQL database and create various tables to store employee, department, project, and other related data. It includes instructions to open a terminal, SSH into a server, connect to the database using psql, and then uses CREATE statements to define the schema, tables, columns, primary keys, and foreign key constraints. Tables are created for employees, departments, department locations, projects, employee work history, and employee dependents.

Uploaded by

TTHUNDERBOLTT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views2 pages

COMPANY DATABASE - Create Table

The document outlines the steps to connect to a PostgreSQL database and create various tables to store employee, department, project, and other related data. It includes instructions to open a terminal, SSH into a server, connect to the database using psql, and then uses CREATE statements to define the schema, tables, columns, primary keys, and foreign key constraints. Tables are created for employees, departments, department locations, projects, employee work history, and employee dependents.

Uploaded by

TTHUNDERBOLTT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Steps to sign-in to the PostgresSQL database:

1. Open terminal
2. ssh [email protected] OR ssh bca@sclabl (Password – bca)
3. psql -U username

Create Schema –
1. CREATE SCHEMA COMPANY
2. set search_path=COMPANY

COMPANY DATABASE

CREATE TABLE EMPLOYEE


(Fname VARCHAR(15) NOT NULL,
Minit CHAR,
Lname VARCHAR(15) NOT NULL, Ssn CHAR(9) NOT NULL,
Bdate DATE,
Address VARCHAR(30), Sex CHAR,
Salary DECIMAL(10,2), Super_ssn CHAR(9),
Dno INT,
PRIMARY KEY (Ssn),
FOREIGN KEY (Super_ssn) REFERENCES EMPLOYEE(Ssn));

CREATE TABLE DEPARTMENT


(Dname VARCHAR(15) NOT NULL,
Dnumber INT NOT NULL, Mgr_ssn CHAR(9) NOT NULL, Mgr_start_date DATE,
PRIMARY KEY (Dnumber),
UNIQUE (Dname),
FOREIGN KEY (Mgr_ssn) REFERENCES EMPLOYEE(Ssn));

---Add foreign key constraint - Dno for the EMPLOYEE table


ALTER TABLE EMPLOYEE ADD FOREIGN KEY(Dno) REFERENCES DEPARTMENT(Dnumber);

CREATE TABLE DEPT_LOCATIONS


(Dnumber INT NOT NULL,
DlocaVon VARCHAR(15) NOT NULL, PRIMARY KEY (Dnumber, DlocaVon),
FOREIGN KEY (Dnumber) REFERENCES DEPARTMENT(Dnumber));

CREATE TABLE PROJECT


( Pname VARCHAR(15) NOT NULL,
Pnumber INT NOT NULL,
PlocaVon VARCHAR(15), Dnum INT NOT NULL,
PRIMARY KEY (Pnumber),
UNIQUE (Pname),
FOREIGN KEY (Dnum) REFERENCES DEPARTMENT(Dnumber));

CREATE TABLE WORKS_ON (Essn CHAR(9) NOT NULL,


Pno INT NOT NULL,
Hours DECIMAL(3,1) NOT NULL,
PRIMARY KEY (Essn, Pno),
FOREIGN KEY (Essn) REFERENCES EMPLOYEE(Ssn), FOREIGN KEY (Pno) REFERENCES
PROJECT(Pnumber));

CREATE TABLE DEPENDENT (Essn CHAR(9) NOT NULL,


Dependent_name VARCHAR(15) NOT NULL,
Sex CHAR,
Bdate DATE,
RelaVonship VARCHAR(8),
PRIMARY KEY (Essn, Dependent_name),
FOREIGN KEY (Essn) REFERENCES EMPLOYEE(Ssn));

You might also like