c# - varchar column sorted by itself -
i have table columns, columns varchar. have noticed rows in table sorted automatically. i, instead, want rows in same order inserted table. clues? please note haven't applied order by
clause , dates same columns.
as evident although added testing book 3 first, automatically came below testing book 2 not desired.
is because pk composite?
you did not specify rdbms using, can following regards microsoft sql server:
you cannot guarantee predictable / repeatable ordering without order clause
if want rows ordered when inserted, need to: add new column either identity (could int or bigint) or datetime / datetime2 datatype default constraint of getdate() or getutcdate() and order new field
the new field has nothing pk. in reference suggestion else made. pk relationships, not sorting, , while identity typically used pk, there plenty of situations have pk of 1 or more non-auto-incrementing fields , still have auto-incrementing field.
if need detail on millisecond / nanosecond records inserted guaranteed / repeatable sort, both datetime / datetime2 , identity fields.
adding one, or both, of these fields not imply specific index structure. existence merely allows create 1 or more indexes include them enforce desired ordering.
Comments
Post a Comment