标签:where
判断如果表不存在,就创建表:
if exists (select * from dbo.sysobjects where id = object_id(N‘[dbo].[tablename]‘) and OBJECTPROPERTY(id, N‘IsUserTable‘) = 1)
begin
CREATE TABLE [dbo].[tablename] (
[FID] [int] NOT NULL ,
[FCode] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[FName] [varchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
[FParentID] [int] NOT NULL ,
[FState] [int] NOT NULL ,
[FType] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
end
判断字段如果不存在,就创建字段:
IF NOT EXISTS (SELECT a.name FROM syscolumns a,sysobjects b
WHERE a.id=b.id
AND LTRIM(a.name)=‘col_name‘ AND LTRIM(b.name)=‘tablename‘)
ALTER TABLE [tablename] ADD [col_name] int NULL
GO
标签:where
原文地址:http://helicon.blog.51cto.com/3926609/1661149