Geeks Talk

Prepare for your Next Interview




stored procedures

This is a discussion on stored procedures within the SQL forums, part of the Databases category; Hi all i have a table called dbo.priorites which contains 2 columns _codepriorite varchar (20) primary key _priorite varchar (50) null so i was asked to change _codepriorite varchar (...


Go Back   Geeks Talk > Databases > SQL

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-01-2008
Junior Member
 
Join Date: Jun 2008
Location: Lebanon
Posts: 12
Thanks: 1
Thanked 2 Times in 2 Posts
ronaldrahme is on a distinguished road
stored procedures

Hi all
i have a table called dbo.priorites which contains 2 columns
_codepriorite varchar (20) primary key
_priorite varchar (50) null

so i was asked to change _codepriorite varchar (20) into _codepriorite int(4)

it worked with this script

alter table dbo.priorites
drop constraint pk_priorites
go

alter table dbo.priorites
drop column _codepriorite
go

alter table dbo.priorites
add _codepriorite int identity
go

alter table dbo.priorites
add primary key (_codepriorite)
go


i wanna use this script from the compiler , like with stored procedures... I wanna call this script from the software im working with... Any ideas on how to do it? ill be thankful for some help...

Last edited by ronaldrahme : 07-01-2008 at 08:47 AM.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-01-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: stored procedures

Do you want to write general script or script specific to this table only?

If it is a general script pass table name and column name as parameter.

You can't execute DDL statements directly in procedures. Use EXECUTE IMMEDIATE to execute above statemetns in procedure.
Reply With Quote
The Following User Says Thank You to krishnaindia2007 For This Useful Post:
  #3 (permalink)  
Old 07-02-2008
Junior Member
 
Join Date: Jun 2008
Location: Lebanon
Posts: 12
Thanks: 1
Thanked 2 Times in 2 Posts
ronaldrahme is on a distinguished road
Re: stored procedures

Thnks krishna for your help
i made a stored proceduren i checked the syntax, it was okay:

create procedure sp_priorites

as
execute immediate
alter table dbo.priorites
drop constraint pk_priorites
go

execute immediate
alter table dbo.priorites
drop column _codepriorite
go

execute immediate alter table dbo.priorites
add _codepriorite int identity
go

execute immediate
alter table dbo.priorites
add primary key (_codepriorite)
go

do you think it might work this way?
Reply With Quote
  #4 (permalink)  
Old 07-02-2008
Junior Member
 
Join Date: Jun 2008
Location: Lebanon
Posts: 12
Thanks: 1
Thanked 2 Times in 2 Posts
ronaldrahme is on a distinguished road
Re: stored procedures

oops its not workin, just another kst> how to use execute immediate? its not working for the above statements
Reply With Quote
  #5 (permalink)  
Old 07-02-2008
Expert Member
 
Join Date: Sep 2007
Posts: 754
Thanks: 22
Thanked 64 Times in 63 Posts
krishnaindia2007 is on a distinguished road
Re: stored procedures

Here is the example

Code:
 
create or replace procedure test_proc as 
string varchar2(100); 

begin 
string := ' alter table test_data add constraint test_data_pk primary key (x)'; 
execute immediate string; 
end; 
/
Reply With Quote
Reply

  Geeks Talk > Databases > SQL


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Procedures Reg. babi_geek Oracle 1 06-04-2008 07:59 AM
Can we use procedures within Views Subashini.Ramasamy SQL 7 02-12-2008 10:08 AM
Stored Procedures in Reports malathim Data Warehousing 0 02-09-2008 05:41 AM
Test cases for testing databases & stored procedures rafina Test Cases 2 08-16-2007 12:37 PM
execute MS-SQL Stored procedures from QTP Geek_Guest QTP 0 06-09-2007 01:53 PM


All times are GMT -4. The time now is 02:41 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved