STRANGE THING HAPPEN WHEN INSERTING AFTER DELETE

  • HELLO, ALL

    i am new to sql server

    so my problem is also little for you but i am confusing please answer

    problem is,

    i have one table with 11 records in it

    nirav 12121

    bhaumik 3345

    nishkal 7676

    anirudhha 697

    nishesh 79876

    donkey 12345

    hkhhl 645

    yahoo 46643

    live 86855

    gongo 3668

    google 9880

    when i insert or update records there is no problem,

    but when i delete lets say row no 6

    THE RESULT LOOK LIKE THIS

    nirav 12121

    bhaumik 3345

    nishkal 7676

    anirudhha 697

    nishesh 79876

    hkhhl 645

    yahoo 46643

    live 86855

    gongo 3668

    google 9880

    and..

    then when i insert a new record it is inserted at 4th position and then the record are continued to be added from that position to downwards

    and not at the end of table(means, not from last record onwards)

    LIKE IF I INSERT WITH STATEMENT

    INSERT INTO try1

    VALUES ('VICKY', 6451)

    RECORD WILL WE LIKE

    nirav 12121

    bhaumik 3345

    nishkal 7676

    anirudhha 697

    nishesh 79876

    VICKY 6451

    hkhhl 645

    yahoo 46643

    live 86855

    gongo 3668

    google 9880

    WHICH IS NOT DESIRED

    AND IT MUST BE LIKE

    nirav 12121

    bhaumik 3345

    nishkal 7676

    anirudhha 697

    nishesh 79876

    hkhhl 645

    yahoo 46643

    live 86855

    gongo 3668

    google 9880

    VICKY 6451

    WHY THIS RESULT IS NOT THERE??

    what happens and what is the solution???:hehe::w00t:

  • SQL Server does not do any ordering by default. If you have a clustered index on the table then usually the data will be returned in the order of the clustered index. I say usually because parallelism can change. The only way to guarantee order in SQL Server is to use the ORDER BY clause. You also need to know if the database collation is case-sensitive and accent-sensitive.

  • Add a column to your table to force the sequence. That can be an Identity field, or a DateAdded field, or anything like that.

    alter table MyTable -- put the real table name here

    add ID int identity primary key

    or

    alter table MyTable -- put the real table name here

    add DateAdded datetime not null default(getdate());

    create clustered index CID_MyTable_DateAdded on dbo.MyTable(DateAdded);

    Of course, where I have "MyTable", put the real table name.

    Either of these will force the data to follow the sequence you want.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

  • Jack Corbett,GSquared

    Thank you all

    Thank you all for your kind reply

    It helps much in my learning phase 😛 🙂

    -----------------------------------------------

    "" GOD IS NOT WITH YOU BUT GOD IS INSIDE YOU "" - 'Pandurang Shastri'

  • You're welcome.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon

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

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