문제

I'm using code like this to create SQL Server CE tables:

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();

Now I need to add an index, too. Do I do it like so:

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();

...(where the command text contains two semi-colon delimited DDL statements) or like so:

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();

...(command, execute, command, execute) or some other way?

도움이 되었습니까?

해결책

Two separate commands. SQL Compact won't allow you to do multiple commands at a time.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top