Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Inserting Row Only at the end of the table

Author  Topic 

khalid.mushtaq
Starting Member

2 Posts

Posted - 2008-12-03 : 04:35:26
I want to insert a row only at the end of the table.

eg:
Suppose i have the following data in the table.

Name | Addr

asdf | #204..
qwere | #450..

So whenever i execute the "INSERT" command for the Table.The data
entered(eg zxccv | #898..) Should be the last row of the table as following:


Name | Addr

asdf | #204..
qwere | #450..
zxccv | #898..


Is there any way to insert data that places the info as the last row of the table always(After Executing Every Single Time) . If yes How?
(No Concurrency)
Thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2008-12-03 : 04:50:46
Not really.
What do you mean by the end of the table?

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-03 : 04:52:10
Usually the chairman sits at the end of the table.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-03 : 05:07:47
If ID is an IDENTITY column, the numbering is done automatically.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-03 : 05:12:31
You REALLY should make the ID column as an IDENTITY column.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-12-03 : 05:19:30
You mean you want the inserted row to have an id 1 greater than the max in the table.

insert tbl
select (select max(id) + 1 from tbl, 'name', 'address'

Could also be done using a trigger.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-03 : 05:32:32
Ordering matters only if you want to show data somewhere
Use Order by ID when you select data


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-12-03 : 05:33:47
quote:
Originally posted by nr

You mean you want the inserted row to have an id 1 greater than the max in the table.

insert tbl
select (select coalesce(max(id),0) + 1 from tbl, 'name', 'address'

Could also be done using a trigger.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.

In case if there are no data

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-03 : 05:37:59
And what about concurrency?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2008-12-03 : 05:40:44
use timestamp to avoid concurrency
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-03 : 05:43:03
And using a timestamp is easier than using an IDENTITY?



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-03 : 06:30:29
OP changes original query after every answer...



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-12-03 : 07:31:39
I cannot see a query posted by OP


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -