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

Ex No 6

The document outlines the creation and manipulation of database tables for employees and departments, including inserting records and creating stored procedures for adding and updating employee information. It also details the creation of an account table with similar operations for managing account balances. The procedures allow for efficient data handling within the database using PL/pgSQL language.

Uploaded by

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

Ex No 6

The document outlines the creation and manipulation of database tables for employees and departments, including inserting records and creating stored procedures for adding and updating employee information. It also details the creation of an account table with similar operations for managing account balances. The procedures allow for efficient data handling within the database using PL/pgSQL language.

Uploaded by

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

EX.

NO:6
ai258113=# create table emp(empno int,ename varchar,job varchar,sal int,deptno int,
hiredate date);
CREATE TABLE
ai258113=# insert into emp values(100,'allen','clerk',1000,20,'1993-06-13');
INSERT 0 1
ai258113=# insert into emp values(101,'ward','salesman',5000,30,'1998-06-15');
INSERT 0 1
ai258113=# insert into emp values(102,'jones','salesman',7000,30,'1996-03-15');
INSERT 0 1
ai258113=# select * from emp;
empno | ename | job | sal | deptno | hiredate
-------+-------+----------+------+--------+------------
100 | allen | clerk | 1000 | 20 | 1993-06-13
101 | ward | salesman | 5000 | 30 | 1998-06-15
102 | jones | salesman | 7000 | 30 | 1996-03-15
(3 rows)

ai258113=# create table dept(deptno int,dname varchar,location varchar);


CREATE TABLE
ai258113=# insert into dept values(10,'accounting','newyork');
INSERT 0 1
ai258113=# insert into dept values(20,'research','dallas');
INSERT 0 1
ai258113=# insert into dept values(30,'sales','chicago');
INSERT 0 1
ai258113=# select * from dept;
deptno | dname | location
--------+------------+----------
10 | accounting | newyork
20 | research | dallas
30 | sales | chicago
(3 rows)

ai258113=# create procedure addemp(a numeric(4,0),b varchar(18),c varchar(18),d


numeric(8,0),e numeric(8,0),f date)
ai258113-# language plpgsql as
ai258113-# $$begin
ai258113$# insert into emp values(a,b,c,d,e,f);
ai258113$# end$$;
CREATE PROCEDURE
ai258113=# call addemp(103,'king','manager',2000,20,'1996-03-05');
CALL
ai258113=# select * from emp;
empno | ename | job | sal | deptno | hiredate
-------+-------+----------+------+--------+------------
100 | allen | clerk | 1000 | 20 | 1993-06-13
101 | ward | salesman | 5000 | 30 | 1998-06-15
102 | jones | salesman | 7000 | 30 | 1996-03-15
103 | king | manager | 2000 | 20 | 1996-03-05
(4 rows)
ai258113=# create procedure updateemp(a numeric(4,0),b numeric(4,0))
ai258113-# language plpgsql as
ai258113-# $$begin
ai258113$# update emp set sal=b where empno=a;
ai258113$# end$$;
CREATE PROCEDURE
ai258113=# call updateemp(102,7000);
CALL
ai258113=# select * from emp;
empno | ename | job | sal | deptno | hiredate
-------+-------+----------+------+--------+------------
100 | allen | clerk | 1000 | 20 | 1993-06-13
101 | ward | salesman | 5000 | 30 | 1998-06-15
103 | king | manager | 2000 | 20 | 1996-03-05
102 | jones | salesman | 7000 | 30 | 1996-03-15
(4 rows)

ai258113=# create table account(ano int,name varchar(20),balance int);


CREATE TABLE
ai258113=# insert into account values(101,'ramu',1000);
INSERT 0 1
ai258113=# insert into account values(102,'somu',2000);
INSERT 0 1
ai258113=# insert into account values(103,'banu',4000);
INSERT 0 1
ai258113=# select * from account;
ano | name | balance
-----+------+---------
101 | ramu | 1000
102 | somu | 2000
103 | banu | 4000
(3 rows)

ai258113=# create procedure add_account(a numeric(8,2),b varchar(18),c numeric


(10,2))
ai258113-# language plpgsql as $$
ai258113$# begin
ai258113$# insert into account values(a,b,c);
ai258113$# end$$;
CREATE PROCEDURE
ai258113=# create procedure update_account(sender numeric(10,2),receiver numeric
(8,2),amount numeric(10,2))
ai258113-# language plpgsql as
ai258113-# $$begin
ai258113$# update account set balance=balance-amount where update_account=sender;
ai258113$# update account set balance=balance+amount where update_account=receiver;
ai258113$# end$$;
CREATE PROCEDURE

You might also like