Monday, March 28, 2011

Select Primary Key

[UPDATE: MS SQL Server 2005]

Hi is it possible to select a bunch of values, and then assign a column in the select statement as the primary key?

SELECT ID FROM HQ AS PRIMARYKEY -- this is wrong
SELECT Names FROM Stores
SELECT PRODUCTNAME FROM PRODUCTS

I ask this because I want to take advantage of the DataRow find method in .net, thank you.

From stackoverflow
  • After populating your dataset, you have to specify the primary key with the DataTable object, not in your sql query.

    myTable.PrimaryKey = new DataColumn[] {
        myTable.Columns["SomeColumn"]
    };
    

    Then you can use the Find() method

    Oliver S : What I was looking for, thank you.
  • No I don't think you can do that, that is have SQL server pass a ready index to the .NET app. You can add an index to the DataTable which will hold the data, it will be build on the client side.

0 comments:

Post a Comment