SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Updating the data in a table


Updating the data in a table

Author
Message
chgn01
chgn01
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2491 Visits: 2034
Comments posted to this topic are about the item Updating the data in a table

--------------------------------------
;-)“Everything has beauty, but not everyone sees it.” ― Confucius
zerko
zerko
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1232 Visits: 712
CAUTION: Assumes you have not set your users 'default schema' to point to something other than 'dbo' - otherwise ....

1. table T1 will be created in the default schema,
2. the update statement may or may not fail, depending on if you also have a suitably specced table named T1 in schema 'dbo', ie dbo.T1 exists, and has a column named 'C1'

and the final select statement will return the unaltered contents of table T1 in your default schema.
Lokesh Vij
Lokesh Vij
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5470 Visits: 1599
For me this was an easy one to attempt :-)

~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter


demonfox
demonfox
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3401 Visits: 1192
Lokesh Vij (2/27/2013)
For me this was an easy one to attempt :-)

+1
not so different for me too .. :-)

thanks for the question :-D

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
Raghavendra Mudugal
Raghavendra Mudugal
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5256 Visits: 2958
Good one. Smile, thank you for posting. (very cute logic...)

i manually iterated the update in mind and 5 OK, 6 OK 7 OK and then for last entry 4 i assumed as 8 and i rushed...Whistling and (you know the rest of it...); for 4 max of C1 is not greater than C1 so the value is the same as original.

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
demonfox
demonfox
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3401 Visits: 1192
Good one. Smile, thank you for posting. (very cute logic...)



yes.. and I think , it would be same as this one

DECLARE @maxc INT

SELECT @maxc = MAX(C1)
FROM dbo.T1

UPDATE T1
SET C1 = C1 + @maxc
FROM T1
WHERE C1 < @maxc



a simpler look :-P

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
Raghavendra Mudugal
Raghavendra Mudugal
SSCertifiable
SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)SSCertifiable (5.3K reputation)

Group: General Forum Members
Points: 5256 Visits: 2958
demonfox (2/28/2013)


yes.. and I think , it would be same as this one



...also significant improvement on the EP.

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
demonfox
demonfox
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3401 Visits: 1192
Raghavendra Mudugal (2/28/2013)
demonfox (2/28/2013)


yes.. and I think , it would be same as this one



...also significant improvement on the EP.

+1 .. a better look , should I have said !!! ;-)

~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one Ermm
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)SSC Guru (132K reputation)

Group: General Forum Members
Points: 132642 Visits: 13347
Nice question, thanks!


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
Stewart "Arturius" Campbell
Stewart "Arturius" Campbell
SSC-Dedicated
SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)SSC-Dedicated (32K reputation)

Group: General Forum Members
Points: 32634 Visits: 7658
Nice back-to-basics question, thanks.
Just a note on the default schema vs. given schema
If the user executing the statement does not have a default schema of dbo, things will get interesting...

____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search