July 1, 2009 at 8:49 am
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
July 1, 2009 at 8:58 am
A table is an unordered set.
July 1, 2009 at 9:06 am
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
July 1, 2009 at 9:07 am
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
July 1, 2009 at 9:17 am
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.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply