Check if a table exists in a SQL Server 2008 database

To check if a table exists in a SQL Server 2008 database, use the following T-SQL code:
Use the system view sys.objects and not the old sql server 2000 system table sysobjects


if
not exists (select 1 from sys.objects o where o.name =’TableName’ and o.type =’U’)
begin
    create table
dbo.TableName (
      
Id int identity(1,1) not nullprimary key,
      
Barcode varchar(35) not null

     )
end
go

Leave a Reply

Your email address will not be published. Required fields are marked *