Friday, 27 September 2013

SQL Syntax error on commented T-SQL only in SQL Server 2012

SQL Syntax error on commented T-SQL only in SQL Server 2012

I had an error occur while installing on a customer site using SQL Server
2012. I was able to reproduce the syntax error locally on SQLExpress 2012.
The same DDL script runs fine under 2008 R2 but fails with "Incorrect
syntax near '44445'".
Checking the SQL that is being executed, the text '44445' is commented
out. Again, this SQL works on 2008 R2. The last line posted is the syntax
offender. Notice, it is commented out as is most of this example.
[snipped]
IF NOT EXISTS (SELECT * FROM ::fn_listextendedproperty(N'Updatable' ,
N'USER',N'dbo', N'TABLE',N'PublishLog', NULL,NULL))
EXEC dbo.sp_addextendedproperty @name=N'Updatable', @value=N'True' ,
@level0type=N'USER',@level0name=N'dbo',
@level1type=N'TABLE',@level1name=N'PublishLog'
GO
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER ON
--GO
--IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[MetaData]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
--BEGIN
--CREATE TABLE [dbo].[MetaData](
-- [ID] [int] IDENTITY(1,1) NOT NULL,
-- [DataName] [nvarchar](255) NULL,
-- [DataDescription] [nvarchar](255) NULL,
-- CONSTRAINT [MetaData_PK] PRIMARY KEY NONCLUSTERED
--(
-- [ID] ASC
--) ON [PRIMARY]
--) ON [PRIMARY]
--END
--GO
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IDENTIFIER OFF
--GO
--IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id =
OBJECT_ID(N'[dbo].[T_MetaData_DTrig]') AND OBJECTPROPERTY(id,
N'IsTrigger') = 1)
--EXEC dbo.sp_executesql @statement = N'CREATE TRIGGER
[dbo].[T_MetaData_DTrig] ON [dbo].[MetaData] FOR DELETE AS
--SET NOCOUNT ON
--/* * PREVENT DELETES IF DEPENDENT RECORDS IN ''DocumentsData'' */
--IF (SELECT COUNT(*) FROM deleted, DocumentsData WHERE (deleted.ID =
DocumentsData.MetaTagsID)) > 0
-- BEGIN
-- RAISERROR 44445 ''The record can''''t be deleted or changed.
Since related records exist in table ''''DocumentsData'''', referential
integrity rules would be violated.''
-- ROLLBACK TRANSACTION
-- END
[snipped]

No comments:

Post a Comment