September 25, 2013 at 10:35 pm
dastagiri16 (9/25/2013)
hi,here i am not able to trust it is updated with 'A'
supose in cte last select statement can be changed to 'AA' it is not showing last updated record that is 'AA'
Thanks,
Dastagiri
In fact, it is only updated once:
http://www.sqlservercentral.com/articles/T-SQL/101464/
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
September 28, 2013 at 7:24 am
I'm sure you was not applying for the job of DBA.
September 29, 2013 at 4:11 pm
dastagiri16 (9/25/2013)
hi,one of the interviewer asked the question about updating...so i have added test table like below...
USE [Practice]
GO
/****** Object: Table [dbo].[mytable] Script Date: 09/25/2013 13:10:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[mytable](
[city] [nchar](10) NULL
) ON [PRIMARY]
GO
and i have inserted values like
insert into mytable (city) values ('A')
so now i want to write update querty to update city value from A to B then B to A by using any query....
Not all questions asked by interviewers have a positive answer. Sometimes they ask the "wrong" thing to see what you'll say.
Also, not all interviewers actually have the knowledge to conduct a proper interview. They might actually but incorrectly believe that you can update the same row more than once in the same "query".
--Jeff Moden
Change is inevitable... Change for the better is not.
September 29, 2013 at 11:08 pm
I have faced the same situation in an interview where interviewer asked me a question on triggers.
I tried my hard to convince him that we have INSTEAD OF and AFTER triggers in MS sql-server, and he was stuck to his point that we also have a BEFORE trigger in MS sql-server.
September 29, 2013 at 11:23 pm
T.Ashish (9/29/2013)
I have faced the same situation in an interview where interviewer asked me a question on triggers.I tried my hard to convince him that we have INSTEAD OF and AFTER triggers in MS sql-server, and he was stuck to his point that we also have a BEFORE trigger in MS sql-server.
In cases like that, after you've made your initial point that you don't think they exist, it is probably best to stick with something non-committal like:
"I'd be fascinated to learn about BEFORE triggers from you some time, but for now I can't comment further because I have no experience with them."
One of the guys on this forum has a saying in his signature link that goes something like:
"Never argue with an idiot. They'll drag you down to their level and they've got a lot more experience operating there."
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
September 30, 2013 at 12:43 am
You are right Dwain.
In such cases, we are mostly in a lose-lose situation. Either we will be rejected as we are not as idiot as we should be, or we will be selected to be ruled by an idiot.
If you are lucky then interviewer will reply at last "I was just cross verifying your knowledge."
October 1, 2013 at 2:31 am
dastagiri16 (9/25/2013)
hi,I have a table like
id city
1 A
so i want to update city column from A to B and again B to A by in single statement..please help.
Thanks
Dastagiri
Some background reading for you.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 1, 2013 at 11:48 am
T.Ashish (9/29/2013)
I have faced the same situation in an interview where interviewer asked me a question on triggers.I tried my hard to convince him that we have INSTEAD OF and AFTER triggers in MS sql-server, and he was stuck to his point that we also have a BEFORE trigger in MS sql-server.
That's when I'd smile, ask them if they have $5 to bet on it and a machine with Books Online on it to prove it. After I'd gotten my $5, I'd walk out of the interview. I've worked a places like that before and I don't want to do that again.
--Jeff Moden
Change is inevitable... Change for the better is not.
October 8, 2013 at 2:01 pm
It seems we've moved into the "Dating Your Employer" thread π
October 8, 2013 at 3:47 pm
Tom Bakerman (10/8/2013)
It seems we've moved into the "Dating Your Employer" thread π
Seems only natural... the original post was an interview question. π
--Jeff Moden
Change is inevitable... Change for the better is not.
October 8, 2013 at 4:16 pm
If you insist doing it "in single statement", how about this:
EXEC (...).
If we'd agree this would qualify as a single statement, we're all set. Right? π
To "support my argument": BOL qualifies EXEC as a statement: ...SQL Server extends the EXECUTE statement...
Of course, this would be a rather pathetic discussion on thin ice, but at least it could bring you in the position of "it depends" (on the definition of the term "statement" in the given context) instead of "it's not possible" at all π
And, as soon as "statement" is defined more precisely as "DML statement", the "back door" is closed and locked leaving a more detailed question:
Based on the example provided by dwain a few posts back, if we update a "left" table in a 1 ..n relationship, will sql server perform n updates or will it just do a single update? Will this example really change the value to 'B' and back to 'A'? How would you verify?
It's a rather weird original question. But with quite some room to open a discussion. Hidden. But available. π
October 8, 2013 at 4:36 pm
LutzM (10/8/2013)
if we update a "left" table in a 1 ..n relationship, will sql server perform n updates or will it just do a single update?
Single.
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
October 8, 2013 at 4:59 pm
GilaMonster (10/8/2013)
LutzM (10/8/2013)
if we update a "left" table in a 1 ..n relationship, will sql server perform n updates or will it just do a single update?Single.
I know. But I thought it would make a good question. π
Unfortunately, answered immediately. :crying: (as it is common here at SSC...)
But the list of questions can be continued:
If it's a single update, which value will be used? Will it be consistent/reproducable or may it vary under certain conditions (e.g. parallelism)?
October 9, 2013 at 1:44 am
LutzM (10/8/2013)
Will it be consistent/reproducable or may it vary under certain conditions (e.g. parallelism)?
The latter. Which is why those many-one updates have such a bad rap (deservedly). It's essentially another order without an order by scenario.
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
October 9, 2013 at 5:00 am
The question asked to OP by interviewer was probably like
"flip the values from A to B and B to A "
was actually answered by "Koen Verbeeck " in his first post here.
AS this is (i often experience this) very frequently asked question to people who are having exp from 3 to 5 yrs.
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Viewing 15 posts - 16 through 30 (of 36 total)
You must be logged in to reply to this topic. Login to reply