我的代码非常简单:
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生成,我只是按原样复制了它。有人可以告诉我为什么这不起作用吗?
谢谢。
您有两次ON [PRIMARY]
,但应该只列出一次。
在 SqlCommand 中使用此脚本。
创建表 [DBO]。[客户数据]([ClientDataID] [int] IDENTITY(1,1( NOT NULL,[SessionID] CHAR NOT NULL,[Browser] varchar NOT NULL,[IP] varchar NOT NULL,[OperatingSystem] varchar NOT NULL,约束 [PK_SessionData] 主键集群([ClientDataID] ASC(WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON( on [primary] (
不确定你是否在寻找这个!
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)
)