How to add a New Row in between the existing rows in a Table using SQL SERVER Mangement Studio

  • How to add a New Row in between the existing rows in a Table using SQL SERVER Mangement Studio.

    For example I have 5 rows in a table.

    Now using SQL SERVER Mnagement Studio, I want to add a row at 3rd position?

    How can I do so?

    Thanks in advance

  • A table is an unordered set.

  • that's what is a main difference between any database system and a flat file/excel spreadsheet.

    SQL server, or any other DataBase Management System, does not guarantee the order of the data unless you specifically have an ORDER BY clause.

    add your new item to your table, and the system decides where and how to store the item based on the primary key of the table, and other storage requirements.

    to get it in a specific order, you need an ORDER BY...

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • What is your key structure on that table?

    If no key then just chose a value that falls between the current 2nd and 3rd positions.

    However, I would say ever table should have a primary key and what exactly are you trying to accomplish.. Please provide more information..

    CEWII

  • Logically, rows in a table are not ordered in any specific way. You would use the ORDER BY clause when you retrieve the rows to deliver them to the application in a specific order. So, if you want to put a row in the physical third position, there isn't a reliable way to do that. If you want a row to show up as the 3rd row when the rows are displayed, place a value in the column you will use in the ORDER BY clause to place it third in the returned set.

    SQL Server has an optimizer that will use indexes, particularly the clustered index, to aid in sorting the rows, but using ORDER By is the only way to guarantee the order you want.


    And then again, I might be wrong ...
    David Webb

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply