Unix Technical Forum

How to check existing table in stored procedure

This is a discussion on How to check existing table in stored procedure within the Sybase forums, part of the Database Server Software category; --> Hello How to check a table is existing or not? I have a stored procedure, which will create a ...


Go Back   Unix Technical Forum > Database Server Software > Sybase

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-08-2008, 07:01 PM
Joe
 
Posts: n/a
Default How to check existing table in stored procedure

Hello

How to check a table is existing or not?

I have a stored procedure, which will create a new table for saving
queried result from two different database table. Before creating a new
table, I want to check the table is generated or not. If the table is
exist, I want to drop the table. Otherwise, a new table will be
generated.

Here is my code in the stored procedure:
IF OBJECT_ID('dbo.procedure_name') IS NOT NULL
BEGIN
IF OBJECT_ID('dbo.procedure_name') IS NOT NULL
DROP PROCEDURE dbo.procedure_name
ELSE
....
END
go

IF EXISTS(select * from sysobjects where name="tablename")
DROP TABLE tablename
go

create proc procedure_name
as
create table temp_tablename
(
....
)
insert
(...)
....

There are no problem on generating and inserting data into new table.
However, there is an error on detecting and dropping the old table.

Does anyone give me some suggestions on my coding? What code I should
put and where should I put it?

Thanks for you help

Joe

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-08-2008, 07:01 PM
wkraatz@csc.com
 
Posts: n/a
Default Re: How to check existing table in stored procedure

You could break it into 3 procedures.

Procedure 1 checks for the existance of the table.
If the table is present, Procedure 1 calls procedure 2.
Procedure 2 drops the table.
Procedure 1 then calls procedure 3 which will create and manipulate the
table.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:51 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com