WEB开发网
开发学院数据库MSSQL Server 用于生成SQL Server数据库对象脚本的选项 阅读

用于生成SQL Server数据库对象脚本的选项

 2008-11-20 10:11:12 来源:WEB开发网   
核心提示: USE [Northwind]GOSET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOCREATE TABLE [dbo].[Categories]([CategoryID] [int] IDENTITY(1,1) NOT NULL,[Category

   USE [Northwind]
  GO
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  CREATE TABLE [dbo].[Categories](
  [CategoryID] [int] IDENTITY(1,1) NOT NULL,
  [CategoryName] [nvarchar](15) NOT NULL,
  [Description] [ntext] NULL,
  [Picture] [image] NULL,
  CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED
  (
  [CategoryID] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

包括IF NOT EXISTS条件从句: 这个设置表示是否在创建一个对象之前检查它是否存在。   USE [Northwind]
  GO
  /****** Object: Table [dbo].[Categories] Script Date: 05/18/2008 21:55:28 ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  IF NOT EXISTS (SELECT * FROM sys.objects WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[Categories]') AND type IN (N'U'))
  BEGIN
  CREATE TABLE [dbo].[Categories](
  [CategoryID] [int] IDENTITY(1,1) NOT NULL,
  [CategoryName] [nvarchar](15) NOT NULL,
  [Description] [ntext] NULL,
  [Picture] [image] NULL,
  CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED
  (
  [CategoryID] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  END

脚本权限:将产生要生成的这个或这些对象所关联的数据库用户和角色权限。   USE [Northwind]
  GO
  /****** Object: Table [dbo].[Categories] Script Date: 05/18/2008 22:04:45 ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  CREATE TABLE [dbo].[Categories](
  [CategoryID] [int] IDENTITY(1,1) NOT NULL,
  [CategoryName] [nvarchar](15) NOT NULL,
  [Description] [ntext] NULL,
  [Picture] [image] NULL,
  CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED
  (
  [CategoryID] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  GO
  GRANT DELETE ON [dbo].[Categories] TO [public]
  GO
  GRANT INSERT ON [dbo].[Categories] TO [public]
  GO
  GRANT REFERENCES ON [dbo].[Categories] TO [public]
  GO
  GRANT SELECT ON [dbo].[Categories] TO [public]
  GO
  GRANT UPDATE ON [dbo].[Categories] TO [public]

脚本索引: 将为要生成的表生成任何关联的索引。      USE [Northwind]
  GO
  /****** Object: Table [dbo].[Categories] Script Date: 05/18/2008 22:11:32 ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  CREATE TABLE [dbo].[Categories](
  [CategoryID] [int] IDENTITY(1,1) NOT NULL,
  [CategoryName] [nvarchar](15) NOT NULL,
  [Description] [ntext] NULL,
  [Picture] [image] NULL,
  CONSTRAINT [PK_Categories] PRIMARY KEY CLUSTERED
  (
  [CategoryID] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
  ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  GO
  /****** Object: Index [CategoryName] Script Date: 05/18/2008 22:11:32 ******/
  CREATE NONCLUSTERED INDEX [CategoryName] ON [dbo].[Categories]
  (
  [CategoryName] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF,
  DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

使用SQL Server管理套件的脚本选项定制工具使你能够让你的脚本如你所需的详细或改进。脚本生成是最适合你的环境的。

上一页  1 2 

Tags:用于 生成 SQL

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接