November 7, 2002 at 10:19 am
hi,
my stored procedure contains a lot of ddl query:
create proc xxxxx
as
CREATE TABLE TAB1 .......
CREATE TABLE TAB2 .......
CREATE TABLE TAB3 .......
.........................
.........................
.........................
.........................
CREATE TABLE TABn .......
go
if a table already exists the stored procedure must exec the next ddl query without raise an exception, it's possible ?
Thanks, anakin
November 7, 2002 at 10:25 am
Try This:
IF NOT EXISTS (SELECT * FROM sysobjects WHERE [Name] = 'TAB1' AND Type = 'U')
BEGIN
CREATE TABLE TAB1 ...
END
-Dan
-Dan
November 7, 2002 at 11:02 am
Or check with
if object_id('tablename') is null
begin
--table name not found create it
end
November 11, 2002 at 12:03 pm
You might want to consider using the INFORMATION_SCHEMA to reference the database objects. These names are not subject to change.
HTH
Steve Hendricks
MCSD, MCDBA
AFS Consulting Group
(949) 588-9800 x15
Steve Hendricks
MCSD, MCDBA
Data Matrix
shendricks@afsconsulting.com
(949) 588-9800 x15
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply