1

我的代码很简单:

SqlCommand command = new SqlCommand("CREATE TABLE [dbo].[ClientData]([ClientDataID] [int] IDENTITY(1,1) NOT NULL,[SessionID] [char](24) NOT NULL,[Browser] [varchar](20) NOT NULL,[IP] [varchar](20) NOT NULL,[OperatingSystem] [varchar](30) NOT NULL,CONSTRAINT [PK_SessionData] PRIMARY KEY CLUSTERED([ClientDataID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY] ON [PRIMARY]");            
using (SqlConnection connection = new SqlConnection(connectionString))
{
    connection.Open();
    command.Connection = connection;
    command.ExecuteNonQuery();
}

执行后,我收到此错误:

关键字“ON”附近的语法不正确

该查询由 MS SQL 2008 生成,我只是照原样复制它。有人可以告诉我为什么这不起作用吗?

谢谢。

4

3 回答 3

3

你有ON [PRIMARY]两次,但它应该只列出一次。

于 2013-10-10T12:07:26.773 回答
0

在 SqlCommand 中使用此脚本。

CREATE TABLE [dbo].[ClientData]([ClientDataID] [int] IDENTITY(1,1) NOT NULL,[SessionID] char NOT NULL,[Browser] varchar NOT NULL,[IP] varchar NOT NULL,[OperatingSystem] varchar NOT NULL,CONSTRAINT [PK_SessionData] PRIMARY KEY CLUSTERED([ClientDataID] ASC)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY])

于 2013-10-11T13:05:43.953 回答
-2

不确定您是否正在寻找这个!

CREATE TABLE [dbo].[ClientData]
(
[ClientDataID] [int] IDENTITY(1,1) 
NOT NULL,[SessionID] [char](24) NOT NULL,
[Browser] [varchar](20) NOT NULL,
[IP] [varchar](20) NOT NULL,
[OperatingSystem] [varchar](30) NOT NULL,
CONSTRAINT [PK_SessionData] 
PRIMARY KEY CLUSTERED([ClientDataID] ASC)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
)
于 2013-10-10T12:12:31.590 回答