You must Sign In to post a response.
  • Category: SQL Server

    Setting sort order on a column

    Hi ,
    I have a column EMPID and few other columns in Employee table. I am inserting data to it for ex: Emp Ids 10, 1 ,4,20. But in my table it should get stored in a sequest like 1,4,10,20.
    Can I do anything while inserting/updating the data so that order will be maintained properly?
    Can we set sort order on a column?
    If I make EMPID as primary key , is it going to resolved this sorting problem?

  • #762755
    Hello Pramod,

    After inserting values to database. You can not reorder the rows but you can reorder the column.

    You must have to do sorting before inserting data to database.

    or else you can reorder the rows when you are retrieving data from the database.

    Hope you understand.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #762756
    Hi Pramood,

    Order the records before insert into database, I assume that your data in datatable, In below code I'm trying to order datatable.

    dt.DefaultView.Sort = "column Desc";

    after sorted out the data insert into your database.

    Give respect to your work, Instead of trying to impress your boss.

    Blog :

  • #762768
    Hai Pramod,
    When you create a clustered index or the primary key to the database table, it will insert the record in sort order for the column which is either Primary key or clustered index.
    But you cant do reordering if the table already contains data.
    Hope it will be helpful to you.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #763218
    while inserting you cant Reorder of the table data.
    using selecting values you can able to reorder of the values


    select * from emloyee oder by empname DESC

    hope this will help


Sign In to post your comments