-1

我在尝试着

  • 如果表不存在则创建一个新表
  • 如果是这样,并且其中没有数据,请插入一些

这是我到目前为止所拥有的:

--See if AuditActivities exists
IF OBJECT_ID('Audit') is not null
--here is where I need to see if either rows are null, if so, enter data
ELSE
CREATE TABLE [dbo].[Audit]
(
AuditSys int,
Description nvarchar(50)
);
4

3 回答 3

0
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Audit]') AND type in (N'U'))
BEGIN
    CREATE TABLE [dbo].[Audit]
    (
        AuditSys int,
        Description nvarchar(50)
    )
END


IF NOT EXISTS (SELECT * FROM [dbo].[Audit])
BEGIN
    --INSERT here
END
于 2013-06-05T16:12:48.353 回答
0
if exists (select * from [Audit])
  begin    
  ...
  end
else
  begin
  ...
  end
于 2013-06-05T16:07:55.067 回答
0
IF OBJECT_ID('Audit') is null
BEGIN
    CREATE TABLE [dbo].[Audit]
    (
    AuditSys int,
    Description nvarchar(50)
    )
END
ELSE 
   IF exists(select * from Audit)
   --insert some record
     INSERT INTO Audit(COL1,COL2,..)
     VALUES (VAL1,VAL2,...)
于 2013-06-05T16:15:23.823 回答