0% found this document useful (0 votes)
75 views3 pages

Dbms Lab # 9 SQL Stored Procedures: Task No 1: Table Creation

This document describes two SQL stored procedures. The first procedure inserts data into a Persons table, and can be called by passing parameter values. The second procedure joins two tables, Departments and Employees, to return the department head and name where the name matches a passed parameter. Samples of creating the tables and procedures, and calling the procedures are provided.

Uploaded by

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

Dbms Lab # 9 SQL Stored Procedures: Task No 1: Table Creation

This document describes two SQL stored procedures. The first procedure inserts data into a Persons table, and can be called by passing parameter values. The second procedure joins two tables, Departments and Employees, to return the department head and name where the name matches a passed parameter. Samples of creating the tables and procedures, and calling the procedures are provided.

Uploaded by

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

DBMS LAB # 9

SQL Stored Procedures

TASK NO 1:
Table Creation
create table Persons
(
P_id int,
Name varchar(20),
Age int,
City varchar(50)
)
select * FROM Persons

Procedure Creation
use Procedures
go
create procedure task1 @P_id int,@Name varchar(20),@Age int,@City varchar(50)
as
insert into Persons
values (@P_id,@Name ,@Age ,@City)
go

Calling Procedure
exec task1 @P_id= 1 ,@Name = 'Shahid' ,@Age= 25, @City= 'D.G.Khan'

exec task1 @P_id= 2 ,@Name = 'Ahmed' ,@Age= 20, @City= ' Multan'

exec task1 @P_id= 3 ,@Name = 'Ali',@Age= 22, @City='multan'


TASK NO 2:
Table Creation(Tbl_Dept)
create table Tbl_Dept
(
D_id int,
D_name varchar(230),
d_head varchar(230),

)
select * FROM Tbl_Dept

Table Creation(Tbl_Emp)
create table Tbl_Emp
(
emp_id int,
emp_name varchar(230),
emp_salary money,
emp_dept int,
)
Procedure Creation
use Procedures
go
create procedure task2 @D_name varchar(30)
as
select Tbl_Dept.d_head,Tbl_Dept.D_name
FROM Tbl_Dept
inner join Tbl_Emp
on Tbl_Dept.D_name= @D_name
go

Calling Procedure
exec task1 @D_name= 'comp eng'

You might also like