Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Q1_ERD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions Q2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
-- This script was generated by a beta version of the ERD tool in pgAdmin 4.
-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.
BEGIN;


CREATE TABLE IF NOT EXISTS public."Customer"
(
cust_id integer NOT NULL,
cust_name text COLLATE pg_catalog."default",
dom_id integer NOT NULL,
CONSTRAINT "Customer_pkey" PRIMARY KEY (cust_id)
);

CREATE TABLE IF NOT EXISTS public."Domain"
(
dom_id integer NOT NULL,
dom_name text COLLATE pg_catalog."default",
CONSTRAINT "Domain_pkey" PRIMARY KEY (dom_id)
);

CREATE TABLE IF NOT EXISTS public."Employee"
(
emp_id integer NOT NULL,
emp_name text COLLATE pg_catalog."default",
title text COLLATE pg_catalog."default",
team_id integer NOT NULL,
CONSTRAINT "Employee_pkey" PRIMARY KEY (emp_id)
);

CREATE TABLE IF NOT EXISTS public."Product"
(
prd_id integer NOT NULL,
prd_name text COLLATE pg_catalog."default",
start_date date,
planned_end_date date,
acctual_end_date date,
team_id integer NOT NULL,
cust_id integer NOT NULL,
CONSTRAINT "Product_pkey" PRIMARY KEY (prd_id)
);

CREATE TABLE IF NOT EXISTS public."Team"
(
team_id integer NOT NULL,
team_name text COLLATE pg_catalog."default",
CONSTRAINT "Team_pkey" PRIMARY KEY (team_id)
);

ALTER TABLE IF EXISTS public."Customer"
ADD FOREIGN KEY (dom_id)
REFERENCES public."Domain" (dom_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;


ALTER TABLE IF EXISTS public."Employee"
ADD FOREIGN KEY (team_id)
REFERENCES public."Team" (team_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;


ALTER TABLE IF EXISTS public."Product"
ADD FOREIGN KEY (team_id)
REFERENCES public."Team" (team_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;


ALTER TABLE IF EXISTS public."Product"
ADD FOREIGN KEY (cust_id)
REFERENCES public."Customer" (cust_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID;

END;
Binary file added Q3_ERD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions Q4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import psycopg2

conn = psycopg2.connect(
host="localhost",
database="W1_Q3_Pagila",
user="postgres",
password="aiham")

cur = conn.cursor()
cur.execute('select * from "actor";')
data = cur.fetchall()
print(data)

print("-----------------------------------------------------------------------------------------------------------------")

cur = conn.cursor()
cur.execute('select * from "category";')
data = cur.fetchone()
print(data)

print("-----------------------------------------------------------------------------------------------------------------")

cur = conn.cursor()
cur.execute('select * from "address";')
data = cur.fetchmany(50)
print(data)
50 changes: 50 additions & 0 deletions exercise5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import psycopg2

conn = psycopg2.connect(
host="localhost",
database="PyCoders",
user="postgres",
password="aiham")
cur = conn.cursor()

cur.execute('CREATE TABLE IF NOT EXISTS public.students(student_id integer NOT NULL,name text );')
cur.execute('CREATE TABLE IF NOT EXISTS public."teachers"(teacher_id integer NOT NULL,name text );')

insert_q = """ INSERT INTO public.students (student_id, name) VALUES (%s,%s)"""
insert_v = (1, 'Ali')
cur.execute(insert_q,insert_v)

insert_q = """ INSERT INTO public.students (student_id, name) VALUES (%s,%s)"""
insert_v = (2, 'Adham')
cur.execute(insert_q,insert_v)

insert_q = """ INSERT INTO public.students (student_id, name) VALUES (%s,%s)"""
insert_v = (3, 'Amal')
cur.execute(insert_q,insert_v)


insert_q = """ INSERT INTO public.teachers (teacher_id, name) VALUES (%s,%s)"""
insert_v = (1, 'Shatha')
cur.execute(insert_q,insert_v)

insert_q = """ INSERT INTO public.teachers (teacher_id, name) VALUES (%s,%s)"""
insert_v = (2, 'Farah')
cur.execute(insert_q,insert_v)

insert_q = """ INSERT INTO public.teachers (teacher_id, name) VALUES (%s,%s)"""
insert_v = (3, 'Sam')
cur.execute(insert_q,insert_v)

cur.execute('select * from "students";')
data = cur.fetchall()
print(data)

cur.execute('select * from "teachers";')
data = cur.fetchall()
print(data)

cur.close()
conn.commit()
conn.close()