Jitender Mahlawat
Jitender Mahlawat

Reputation: 3102

What will be the order of select statement by default

If I insert a set of Row in a table variable . After that I select * from table in which order it will give me output .is it will be order of insertion of will it change

    DECLARE @next_seq_val NCHAR(50)
    DECLARE @tbl TABLE(
    seq NCHAR(50)
    )
    EXEC    [dbo].[ix_NextSeq]
        @seq_id = 58,
        @next_seq_val = @next_seq_val OUTPUT
   insert into @tbl(seq) values(@next_seq_val)
   SELECT * FROM @tbl

Upvotes: 0

Views: 151

Answers (2)

kdani
kdani

Reputation: 847

It should be considered as random order. It depends on the database server.

Upvotes: 0

user330315
user330315

Reputation:

Rows in a table are not sorted. There is no "default" order. The database is free to return them in any order it finds most efficient.

Think of rows in a table like balls in a basket, they don't have an order either.

The only (really!) way to ensure a consistent order is to use ORDER BY

Upvotes: 2

Related Questions