Click here to monitor SSC
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
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1729 Visits: 1792
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
SSC Eights!
SSC Eights! (954 reputation)SSC Eights! (954 reputation)SSC Eights! (954 reputation)SSC Eights! (954 reputation)SSC Eights! (954 reputation)SSC Eights! (954 reputation)SSC Eights! (954 reputation)SSC Eights! (954 reputation)

Group: General Forum Members
Points: 954 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
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1712 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
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1299 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
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1756 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
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1299 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
SSCommitted
SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)SSCommitted (1.8K reputation)

Group: General Forum Members
Points: 1756 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
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1299 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
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18399 Visits: 13247
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
SSCertifiable
SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)SSCertifiable (6.3K reputation)

Group: General Forum Members
Points: 6251 Visits: 7188
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