Inserting value in database table in sql server 2008?
-
i am trying to insert values in a table in sql server 2008 the value inserts successfully but the problem is that, the values stores in random order. not in the order in which i inserted value in table
-
Answer:
SQL makes no guarantees about the order records are stored in. While an identity column will give you a column to sort on in the order the items were inserted, even those may come back in a different order if you don't specify a sort order.
amit at Yahoo! Answers Visit the source
Other answers
what is meaning of random are you talking about columns or Row if columns insert proper values here insert into table(column1, column2...) values (val1, val2....) if its row its does not affect on your application if you are want order in application you have to write manual code if you are want order in SQL server you can set order as you want if you are want order number in auto number field so it will come in order if you does not delete any row if you are delete any row it will never repeat in auto - number field...
To store the value in a specific order you need to create a identity column in the table and while retrieving the data use order by on the identity column.
Have you defined a primary key, autonumber and/or indexes against the table? Without using one, there's no implicit ordering of rows within a table. With one or more such existing, the optimizer may or may not select one to use depending on what it judges will be the most efficient. In any case, there's no way to accurately predict the order of resultset rows without an explicit ORDER BY.
Related Q & A:
- How to connect Sql Server Database from android app?Best solution by Stack Overflow
- Does it ever make sense to use RAM Disk to force RAM allocation for tempdb with SQL Server 2008?Best solution by Database Administrators
- How to Restrict Database for One User in SQL Server 2008 R2?Best solution by Database Administrators
- How to add primary key from multiple table as a foreign key in a table in sql server 2008?Best solution by stackoverflow.com
- How to enable remote connections in SQL Server 2008?Best solution by Server Fault
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.