Consider the following database
Project (pno int, pname char (30), ptype char (20), duration int)
Employee (empno int, ename char (20), joining_date date)
The relationship between Project and Employee is many to many with descriptive attribute start_date.
Create Table Project
Project (pno int, pname char (30), ptype char (20), duration int)
create table project1 (pno int primary key , pname varchar(50),ptype varchar (20), duration integer );
Insert values in Project table
insert into project1 values(1,'aa','game ' , 25 );
insert into project1 values(2,'bb','appliaction ' , 30 );
insert into project1 values(3,'cc','website ' , 45 );
insert into project1 values(4,'dd','robtotic ' , 35 );
Output of Table
Acode3=# select * from project;
o\p
Acode3=# select * from project;
pno | pname | ptype | duration
-----+-------+--------------+----------
1 | aa | game | 25
2 | bb | appliaction | 30
3 | cc | website | 45
4 | dd | robtotic | 35
(4 rows)
Create tabel Employee
Employee (empno int, ename char (20), joining_date date)
create table employee3 (eno int primary key, ename varchar(50), salary float,dateJ date );
Insert values in Employee
insert into employee3 values (1,'Acode',15000.00 ,'2020-04-28');
insert into employee3 values (2,'mujju',20000.00,'2020-05-21' );
insert into employee3 values (3,'adharsh', 25000,'2020-04-21');
insert into employee3 values (4,'rohan',26000,'2019-04-12');
Output of table
Acode3=# select * from employee3;
o\p
Acode3=# select * from employee3;
eno | ename | salary | datej
-----+---------+--------+------------
1 | Acode | 15000 | 2020-04-28
2 | mujju | 20000 | 2020-05-21
3 | adharsh | 25000 | 2020-04-21
4 | rohan | 26000 | 2019-04-12
(4 rows)
Create table(Pro) M-M relationship
create table pro ( eno int references employee3 (eno),pno int references project1 (pno));
Insert values in Pro table
insert into pro values ( 1,1 );
insert into pro values ( 1,2 );
insert into pro values ( 1,3 );
insert into pro values ( 1,4 );
insert into pro values ( 2,1 );
insert into pro values ( 2,3 );
insert into pro values ( 2,2 );
insert into pro values ( 2,4 );
insert into pro values ( 3,1 );
insert into pro values ( 3,3 );
insert into pro values ( 3,4 );
insert into pro values ( 4,4 );
insert into pro values ( 4,3 );
insert into pro values ( 4,2 );
insert into pro values ( 4,1 );
Output of tabel
Acode3=# select * from pro;
o\p
Acode3=# select * from pro;
eno | pno
-----+-----
1 | 1
1 | 1
1 | 2
1 | 3
1 | 4
2 | 1
2 | 3
2 | 2
2 | 4
3 | 1
3 | 3
3 | 4
4 | 4
4 | 3
4 | 2
4 | 1
(16 rows)
0 Comments