January 20, 2016 at 2:19 pm
HI ALL
I'm new in T-SQL so i need your help
My problem is : After deleting a row , is there a way to retrieve the ID of that row ?
Because i want to assign this ID to another customer in my customer's table
Thanks
January 20, 2016 at 2:31 pm
abdellahmoh2016 (1/20/2016)
HI ALLI'm new in T-SQL so i need your help
My problem is : After deleting a row , is there a way to retrieve the ID of that row ?
Because i want to assign this ID to another customer in my customer's table
Thanks
Quick suggestion, use the output clause with the delete statement to insert the ID value into a table of "available" Ids.
😎
January 20, 2016 at 2:50 pm
My question would be 'why'?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 20, 2016 at 2:51 pm
GilaMonster (1/20/2016)
My question would be 'why'?
+1000
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
January 20, 2016 at 3:10 pm
GilaMonster (1/20/2016)
My question would be 'why'?
+1
😎
Didn't want to open that Pandora's box
January 22, 2016 at 8:10 pm
Hi Thank you for your reply
It's because my boss suggested me simple like that
January 22, 2016 at 11:12 pm
abdellahmoh2016 (1/22/2016)
Hi Thank you for your replyIt's because my boss suggested me simple like that
Quite frankly, your boss does not know what he/she is talking about. Reuse of ID's like this simply a bad practice. What about historical records that have this ID? What about child tables that use this ID? If this is an Identity column, well, you are just asking for more pain.
I see a lot of potential for either deadlocking (multiple concurrent connections trying to do an "insert") or just plain performance overhead by first having to check if there is an available empty row first, then insert later. You have just increased the complexity of your application significantly, for what, sequential numbers? Do yourself and the people who will inherit this application a huge favor and forget about this. Furthermore, if you use foreign keys, this could really create some horribly inconsistent data.
Good luck.
__________________________________________________________________________________________________________
How to Post to get the most: http://www.sqlservercentral.com/articles/Best+Practices/61537/
January 22, 2016 at 11:54 pm
abdellahmoh2016 (1/22/2016)
It's because my boss suggested me simple like that
Then I would suggest that you suggest to your boss that this is a bad idea, overly complicated, makes auditing hell and has no real benefit.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 23, 2016 at 5:55 am
abdellahmoh2016 (1/22/2016)
Hi Thank you for your replyIt's because my boss suggested me simple like that
Tell your boss to stick to defining functionality, and leave the implementation to those who are paid to know technical details - i.e. you
Or if he/she thinks he/she knows better, give them your chair and tell them to do it themself.
January 23, 2016 at 9:34 am
Piling on, I have to agree with the majority opinion here - this is a bad idea. If you're going to reuse IDs that are primary keys, this will lead to more problems later in life. Like Gail said, if you're auditing, your life is going to become much more complicated.
January 23, 2016 at 9:45 am
Ed Wagner (1/23/2016)
Piling on, I have to agree with the majority opinion here - this is a bad idea. If you're going to reuse IDs that are primary keys, this will lead to more problems later in life. Like Gail said, if you're auditing, your life is going to become much more complicated.
Well we can probably all picture a desk with five perfectly sharpened pencils, one for each day of the week, aligned perfectly 90 degr. from the upper edge, perfect untouched notepad positioned 1.75 inches from the pencils..... and an unbroken sequence of customer ID's in the database....
😎
January 23, 2016 at 9:49 am
Eirikur Eiriksson (1/23/2016)
Ed Wagner (1/23/2016)
Piling on, I have to agree with the majority opinion here - this is a bad idea. If you're going to reuse IDs that are primary keys, this will lead to more problems later in life. Like Gail said, if you're auditing, your life is going to become much more complicated.Well we can probably all picture a desk with five perfectly sharpened pencils, one for each day of the week, aligned perfectly 90 degr. from the upper edge, perfect untouched notepad positioned 1.75 inches from the pencils..... and an unbroken sequence of customer ID's in the database....
😎
Absolutely. But in what order would the pencils be placed on the table? In what order would you be required to pick them up. 😛
January 23, 2016 at 10:00 am
Ed Wagner (1/23/2016)
Eirikur Eiriksson (1/23/2016)
Ed Wagner (1/23/2016)
Piling on, I have to agree with the majority opinion here - this is a bad idea. If you're going to reuse IDs that are primary keys, this will lead to more problems later in life. Like Gail said, if you're auditing, your life is going to become much more complicated.Well we can probably all picture a desk with five perfectly sharpened pencils, one for each day of the week, aligned perfectly 90 degr. from the upper edge, perfect untouched notepad positioned 1.75 inches from the pencils..... and an unbroken sequence of customer ID's in the database....
😎
Absolutely. But in what order would the pencils be placed on the table? In what order would you be required to pick them up. 😛
Elementary Ed, one after the other...
😎
January 23, 2016 at 12:15 pm
Eirikur Eiriksson (1/23/2016)
Ed Wagner (1/23/2016)
Eirikur Eiriksson (1/23/2016)
Ed Wagner (1/23/2016)
Piling on, I have to agree with the majority opinion here - this is a bad idea. If you're going to reuse IDs that are primary keys, this will lead to more problems later in life. Like Gail said, if you're auditing, your life is going to become much more complicated.Well we can probably all picture a desk with five perfectly sharpened pencils, one for each day of the week, aligned perfectly 90 degr. from the upper edge, perfect untouched notepad positioned 1.75 inches from the pencils..... and an unbroken sequence of customer ID's in the database....
😎
Absolutely. But in what order would the pencils be placed on the table? In what order would you be required to pick them up. 😛
Elementary Ed, one after the other...
😎
Wouldn't that by PBAP?
(Pencil By Agonizing Pencil)
I'd pick them up all at once, in one single set-babsed sweep.
January 23, 2016 at 1:15 pm
Hugo Kornelis (1/23/2016)
Eirikur Eiriksson (1/23/2016)
Ed Wagner (1/23/2016)
Eirikur Eiriksson (1/23/2016)
Ed Wagner (1/23/2016)
Piling on, I have to agree with the majority opinion here - this is a bad idea. If you're going to reuse IDs that are primary keys, this will lead to more problems later in life. Like Gail said, if you're auditing, your life is going to become much more complicated.Well we can probably all picture a desk with five perfectly sharpened pencils, one for each day of the week, aligned perfectly 90 degr. from the upper edge, perfect untouched notepad positioned 1.75 inches from the pencils..... and an unbroken sequence of customer ID's in the database....
😎
Absolutely. But in what order would the pencils be placed on the table? In what order would you be required to pick them up. 😛
Elementary Ed, one after the other...
😎
Wouldn't that by PBAP?
(Pencil By Agonizing Pencil)
I'd pick them up all at once, in one single set-babsed sweep.
And glue them on each finger for asynchronous writing...:w00t:
😎
Viewing 15 posts - 1 through 15 (of 21 total)
You must be logged in to reply to this topic. Login to reply