diff --git a/Q1_ERD.png b/Q1_ERD.png new file mode 100644 index 0000000..d4ddf09 Binary files /dev/null and b/Q1_ERD.png differ diff --git a/Q2.txt b/Q2.txt new file mode 100644 index 0000000..dab1479 --- /dev/null +++ b/Q2.txt @@ -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; \ No newline at end of file diff --git a/Q3_ERD.png b/Q3_ERD.png new file mode 100644 index 0000000..e81bc3d Binary files /dev/null and b/Q3_ERD.png differ diff --git a/Q4.py b/Q4.py new file mode 100644 index 0000000..b991c4b --- /dev/null +++ b/Q4.py @@ -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) \ No newline at end of file diff --git a/exercise5.py b/exercise5.py new file mode 100644 index 0000000..631f38a --- /dev/null +++ b/exercise5.py @@ -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() + +