请帮忙解读一下这个mssql脚本每句的含义以及整个脚本的用法
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AutoDuty]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AutoDuty]
GO
CREATE TABLE [dbo].[AutoDuty] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[AutoType] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ,
[AutoContent] [nvarchar] (60) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[RTime] [datetime] NOT NULL ,
[OTime] [datetime] NULL ,
[IsOk] [int] NOT NULL ,
[Notes] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AutoDuty] WITH NOCHECK ADD
CONSTRAINT [PK_AutoNotice] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AutoDuty] ADD
CONSTRAINT [DF_AutoDuty_AutoType] DEFAULT ('喊话') FOR [AutoType],
CONSTRAINT [DF_AutoNotice_RTime] DEFAULT (getdate()) FOR [RTime],
CONSTRAINT [DF_AutoNotice_IsOk] DEFAULT (0) FOR [IsOk]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AutoSystem]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[AutoSystem]
GO
CREATE TABLE [dbo].[AutoSystem] (
[AutoOpen] [int] NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[AutoSystem] ADD
CONSTRAINT [DF_AutoSystem_AutoOpen] DEFAULT (0) FOR [AutoOpen]
GO
insert into AutoSystem ([AutoOpen]) values ('1')
------解决方案--------------------判断表是否存在
如果存在删除之
建立表
添加主键约束
添加默认值约束
下面同上
------解决方案--------------------
SQL code
--功过系统表来判断该名称的表是否存在
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AutoDuty]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
--存在删除该表
drop table [dbo].[AutoDuty]
GO
--创建表语法
CREATE TABLE [dbo].[AutoDuty] (
[ID] [int] IDENTITY (1, 1) NOT NULL , --自增列的创建
[AutoType] [char] (10) COLLATE Chinese_PRC_CI_AS NULL , --指定排序规则,详细可以查资料
[AutoContent] [nvarchar] (60) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[RTime] [datetime] NOT NULL , --NOT NULL约束
[OTime] [datetime] NULL ,
[IsOk] [int] NOT NULL ,
[Notes] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
--添加约束 (主键约束)
ALTER TABLE [dbo].[AutoDuty] WITH NOCHECK ADD
CONSTRAINT [PK_AutoNotice] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO
--添加约束 DEFAULT 的默认值约束
ALTER TABLE [dbo].[AutoDuty] ADD
CONSTRAINT [DF_AutoDuty_AutoType] DEFAULT ('喊话') FOR [AutoType],
CONSTRAINT [DF_AutoNotice_RTime] DEFAULT (getdate()) FOR [RTime],
CONSTRAINT [DF_AutoNotice_IsOk] DEFAULT (0) FOR [IsOk]
GO