Question : How do I check if a table exists, before creating the table...

NOTE:  This is SQL 2000.  There is NO zone for SQL2000 so I put it into 2005


I am trying to check to see if the table exists before creating the table.  This is how I am trying to do it now.

I get this error when I try to run it...

Server: Msg 208, Level 16, State 1, Line 1
Invalid object name 'sys.objects'.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
/****** Object:  Table [dbo].[loginfo]    Script Date: 11/12/2009 17:44:56 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[loginfo]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[loginfo](
	[username] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[logintime] [datetime] NULL,
	[page] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[browser] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[platform] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[sourceip] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
	[status] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
)
END
GO

Answer : How do I check if a table exists, before creating the table...

use sysobjects instead of sys.objects
Random Solutions  
 
programming4us programming4us