【问题标题】:How can I add an index to a SQL Server CE table created programmatically?如何向以编程方式创建的 SQL Server CE 表添加索引?
【发布时间】:2013-12-06 22:55:23
【问题描述】:

我正在使用这样的代码来创建 SQL Server CE 表:

command.CommandText = "CREATE TABLE InventoryItems (Id nvarchar(50) NOT NULL, PackSize smallint NOT NULL, Description nvarchar(255), DeptDotSubdept float, UnitCost float, UnitList float, UPCCode nvarchar(50), UPCPackSize smallint, CRVId int);";
command.ExecuteNonQuery();

现在我也需要添加一个索引。我是这样做的吗:

command.CommandText = "CREATE TABLE InventoryItems (Id nvarchar(50) NOT NULL, PackSize smallint NOT NULL, Description nvarchar(255), DeptDotSubdept float, UnitCost float, UnitList float, UPCCode nvarchar(50), UPCPackSize smallint, CRVId int);
CREATE INDEX idxUnitCost ON InventoryItems (UnitCost) ASC";
command.ExecuteNonQuery();

...(其中命令文本包含两个分号分隔的 DDL 语句)或类似:

command.CommandText = "CREATE TABLE InventoryItems (Id nvarchar(50) NOT NULL, PackSize smallint NOT NULL, Description nvarchar(255), DeptDotSubdept float, UnitCost float, UnitList float, UPCCode nvarchar(50), UPCPackSize smallint, CRVId int);"
command.ExecuteNonQuery();

command.CommandText = "CREATE INDEX idxUnitCost ON InventoryItems (UnitCost) ASC";
command.ExecuteNonQuery();

...(命令,执行,命令,执行)或其他方式?

【问题讨论】:

    标签: sql sql-server-ce compact-framework windows-ce ddl


    【解决方案1】:

    两个单独的命令。 SQL Compact 不允许您一次执行多个命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-02
      • 2012-04-19
      • 2013-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多