Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Scripting new tables

Author  Topic 

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-03-09 : 10:57:44
Hi all.

I am looking to write a script to create several new tables. What i would like to know is how do i check if they already exist before i create them and if they already exist dont create them? If they dont exist, create them.

Cheers people.

cas_o
Posting Yak Master

154 Posts

Posted - 2007-03-09 : 11:00:43
[CODE]
if NOT exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[myTable]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
create table myTable
(
id int identity(1,1) primary key
)
end


[/CODE]

;-]... Quack Waddle
Go to Top of Page

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-03-09 : 11:20:16
Great stuff mate.

Thanks very much!
Go to Top of Page
   

- Advertisement -