小编典典

此SQL创建表语句有什么问题?

sql

此SQL查询是由SQL Server Managment Studio生成的,它引发了一个错误:

USE [database_name]
GO
/****** Object:  Table [dbo].[UserAddress]    Script Date: 02/17/2010 11:21:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[UserAddress]
(
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [UserID] [int] NULL,
    [AddressName] [nvarchar](25) NULL,
    [Fname] [nvarchar](15) NULL,
    [LName] [nvarchar](20) NULL,
    [City] [nvarchar](15) NULL,
    [Street] [nvarchar](30) NULL,
    [StreetNum] [nvarchar](5) NULL,
    [FloorNum] [int] NULL,
    [AptNum] [int] NULL,
    [ZipCode] [int] NULL,
    [Phone] [varchar](15) NULL,
    [Phone_Prefix] [int] NULL,
    [CellPhone] [varchar](15) NULL,
    [CellPhone_Prefix] [int] NULL,
    [Fax] [varchar](15) NULL,
    [Fax_Prefix] [int] NULL,
    [Primary] [bit] NULL,
    CONSTRAINT [PK_UserAddress] 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
SET ANSI_PADDING OFF

错误是:Msg 170, Level 15, State 1, Line 27 Line 27: Incorrect syntax near '('.指向[CellPhone_Prefix] [int] NULL,但我觉得这行没问题。
有什么事吗
编辑:
我只是注释掉

 CONSTRAINT [PK_Users] PRIMARY KEY CLUSTERED 
(
    [ID] ASC,
    [ClientStoreID] ASC,
    [Uname] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

现在可以了,为什么呢?
编辑2:
我将其范围缩小到:

WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]

我在这里想念什么吗?


阅读 186

收藏
2021-04-28

共1个答案

小编典典

我认为这取决于SQL Server数据库版本。

我尝试对SQL Server 2000数据库使用SSMS 2005进行查询,但由于您描述的相同错误而失败。

当我连接到SQL Server 2005服务器时,查询将完美执行。

您是否确实检查过服务器版本,而不仅仅是SSMS版本。

根据SQL Server 2000语法,WITH部分仅允许设置FillFactor,而没有其他设置:

< table_constraint > ::= [ CONSTRAINT constraint_name ]
{ [ { PRIMARY KEY | UNIQUE }
    [ CLUSTERED | NONCLUSTERED ]
    { ( column [ ASC | DESC ] [ ,...n ] ) }
    [ WITH FILLFACTOR = fillfactor ]
    [ ON { filegroup | DEFAULT } ]
]

这不同于SQL Server 2008中/
2005年的语法,它允许括号内的多个选项:

< table_constraint > ::= [ CONSTRAINT constraint_name ] 
{  { PRIMARY KEY | UNIQUE } 
    [ CLUSTERED | NONCLUSTERED ] 
    (column [ ASC | DESC ] [ ,...n ] ) 
    [ WITH FILLFACTOR = fillfactor | WITH ( <index_option> [ , ...n ] ) ]
    [ ON { partition_scheme_name (partition_column_name) | filegroup | "default" } ] 
    .
    .
    .
}
2021-04-28