DNN SQL数据提供程序语法问题

时间:2017-09-21 14:20:13

标签: sql-server dotnetnuke

我是DNN模块开发和Web开发人员的新手。安装模块时,我在“ALTER TABLE”附近遇到语法错误。我已经使用了Chris Hammond指南中列出的步骤。 DNN Guide

这是我的代码

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}[{objectQualifier}name_table]') and OBJECTPROPERTY(id, N'IsTable') = 1)
BEGIN
CREATE TABLE {databaseOwner}[{objectQualifier}name_table](
    [file_name] [nchar](50) NOT NULL,
    [guid_key] [uniqueidentifier] NOT NULL,

ALTER TABLE {databaseOwner}[{objectQualifier}name_table] ADD CONSTRAINT [PK_{databaseOwner}{objectQualifier}name_table] PRIMARY KEY CLUSTERED ([guid_key])

END
GO

1 个答案:

答案 0 :(得分:1)

我认为问题在于您在create table语句中嵌套了Alter语句。它应该是这样的,在create table中有约束。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}name_table]') AND type in (N'U'))
BEGIN
CREATE TABLE {databaseOwner}[{objectQualifier}name_table](
    [file_name] [nchar](50) NOT NULL,
    [guid_key] [uniqueidentifier] NOT NULL,
 CONSTRAINT [PK_{objectQualifier}name_table] PRIMARY KEY CLUSTERED ( [guid_key] )
)
END
GO

或分开

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}name_table]') AND type in (N'U'))
BEGIN
CREATE TABLE {databaseOwner}[{objectQualifier}name_table](
    [file_name] [nchar](50) NOT NULL,
    [guid_key] [uniqueidentifier] NOT NULL
)
END
GO

ALTER TABLE {databaseOwner}[{objectQualifier}name_table] ADD CONSTRAINT [PK_{databaseOwner}{objectQualifier}name_table] PRIMARY KEY CLUSTERED ([guid_key])
GO