2012-08-08 121 views
1

在MS SQL Server 2008(10.50.2811.0)開發人員版(64位)上,在Windows 2008 Server 2008 R2 Standard下運行SQL Server Management Studio會創建多次丟棄相同約束的腳本。使用約束時,MS SQL Server 2008腳本生成會創建無效腳本

一個簡單的例子包括兩個表tParent和tChild,其中tChild的ParentID引用tParent的ID。該腳本(數據庫上下文菜單=>任務=>生成腳本...)生成(用於刪除並創建)看起來是這樣的:

USE [TestDb] 
GO 
/****** Object: ForeignKey [FK_tChild_tParent] Script Date: 08/08/2012 08:11:51 ******/ 
ALTER TABLE [dbo].[tChild] DROP CONSTRAINT [FK_tChild_tParent] 
GO 
/****** Object: Table [dbo].[tChild] Script Date: 08/08/2012 08:11:51 ******/ 
ALTER TABLE [dbo].[tChild] DROP CONSTRAINT [FK_tChild_tParent] 
GO 
DROP TABLE [dbo].[tChild] 
GO 
/****** Object: Table [dbo].[tParent] Script Date: 08/08/2012 08:11:52 ******/ 
DROP TABLE [dbo].[tParent] 
GO 
/****** Object: Table [dbo].[tParent] Script Date: 08/08/2012 08:11:52 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
CREATE TABLE [dbo].[tParent](
[ID] [int] IDENTITY(1,1) NOT NULL, 
[Name] [varchar](50) NOT NULL, 
[Value] [int] NOT NULL, 
CONSTRAINT [PK_tParent] PRIMARY KEY CLUSTERED 
(
[ID] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 
GO 
/****** Object: Table [dbo].[tChild] Script Date: 08/08/2012 08:11:51 ******/ 
SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 
CREATE TABLE [dbo].[tChild](
[ID] [int] IDENTITY(1,1) NOT NULL, 
[ParentID] [int] NOT NULL, 
[Name] [varchar](50) NOT NULL, 
[Value] [int] NOT NULL, 
CONSTRAINT [PK_tChild] PRIMARY KEY CLUSTERED 
(
[ID] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 
GO 
/****** Object: ForeignKey [FK_tChild_tParent] Script Date: 08/08/2012 08:11:51 ******/ 
ALTER TABLE [dbo].[tChild] WITH CHECK ADD CONSTRAINT [FK_tChild_tParent] FOREIGN KEY([ParentID]) 
REFERENCES [dbo].[tParent] ([ID]) 
GO 
ALTER TABLE [dbo].[tChild] CHECK CONSTRAINT [FK_tChild_tParent] 
GO 

爲什麼有兩個相同的線,這兩個嘗試刪除該FK_tChild_tParent約束?爲什麼兩條線的評論都不一樣?

回答

1

出現它是一個已知的錯誤,在Microsoft Connect引用此處。

我可以確認SQL2012上不存在重複的行爲。

+0

謝謝,所以時間會解決它:-) – Gorgsenegger 2012-11-04 16:38:31

相關問題