March 18, 2011 at 8:15 am
Good point Hugo.
Thanks.
Do you have clue on the additional comma which just before the closing bracket (i.e. Amount INT,)?
March 18, 2011 at 8:15 am
Great question...a lot of points to ponder!
I had no problem with the implicit conversions.
I'm fascinated to learn you can use data types as column names.
(This is good to know so you don't do it unintentionally, not because it's something you would want to do intentionally.)
I'm still very puzzled why the extra comma didn't cause the create table statement to fail.
March 18, 2011 at 8:16 am
paul.jones (3/18/2011)
I was so convinced the extra comma in the CREATE TABLE would cause an error, I never even noticed the date of the 2nd of Chequary (Chequary is the month after December where you still write cheques with the wrong year on).So, why is it OK to have the extra comma? In BOL http://msdn.microsoft.com/en-us/library/ms174979.aspx doesn't the [,...n] bit mean you can have a comma followed by another column definition, but not just a comma on its own? Why does having 2 commas at the end fail but one is OK?
I love the "chequary" comment!
I don't know why the extra comma doesn't cause an error, but I do like it as a (probably uninteded) feature. I can write CREATE TABLE statements like this:
CREATE TABLE TabName(
Column1 datatype NOT NULL,
Column2 datatype NOT NULL,
Column3 datatype NOT NULL,
CONSTRAINT xxx PRIMARY KEY (Column1),
CONSTRAINT yyy FOREIGN KEY (Column2) REFERENCES SomeTable
);
I can easily comment or uncomment lines, and even if I comment the last line, I can still run the code with no error, without having to remember to remove the comma from the last uncommented line.
March 18, 2011 at 8:18 am
Surii (3/18/2011)
Chris Houghton (3/18/2011)
I'm half asleep this morning. Missed every one of the potential gotchas (implict conversion, US date format and extra comma), thought "this code looks ok" and selected the right answer. If i'd been more awake I'd have got the answer wrong on several counts 😀Same case with me..:w00t:
Definitely an advantage to be a groggy, hung-over American in this one.
March 18, 2011 at 8:39 am
jcunningham (3/18/2011)
I see I am not the only one who noticed the extra comma. Did the author plan for this to throw people off??
Yes I did
March 18, 2011 at 8:44 am
Honestly, I guessed and got it right, not closed-my-eyes-and-threw-a-dart guessed, but the code just looked like it could work. If I had read carefully, I think I would have said it could not work because of the extra comma. I almost balked at the select inside the insert as I have not used this myself but it looked plausible so I went for it.
So I learned AND got a point 🙂 Thanks for the question.
Peter Trast
Microsoft Certified ...(insert many literal strings here)
Microsoft Design Architect with Alexander Open Systems
March 18, 2011 at 8:49 am
Bull, theres a comma at the end of the create. That will fail.
March 18, 2011 at 8:49 am
bitbucket-25253 (3/18/2011)[hr
Yes I did
It worked!
Did you find any explanation of this behaviour?
March 18, 2011 at 8:57 am
Ryan Fitzgerald (3/18/2011)
Bull, theres a comma at the end of the create. That will fail.
In my best master Yoda voice, "Sure of this, are you?"
March 18, 2011 at 8:57 am
Hugo Kornelis (3/18/2011)
When will people ever learn about date formats?The correct answer ("depends on the locale settings") was not listed, so I had to throw a coin to choose between theory a (question submitted by a stupid American or Japanese who thinks the US/Jap system is the only system) or theory b (question submitted by a stupic non-American/non-Japanese who thinks THEIR system is the only system).
Note to anyone who ever intends to submit questions with hardcoded dates in them: please use the yyyymmdd format only! Or, if you need time as well, yyyy-mm-ddThh:mm:ss.
If you really want to tick people off by using a different date format, then FIRST run your code with a SET LANGUAGE statement in front of it, trying all the major languages - then consider if you still want to keep your code that way.
THANKS FOR CALLING ME STUPID. YOUR ARROGANCE OR SHOULD I SAY EGOTISM IS APPALLING.
As aside, you really should spell check your work before posting or is "stupic" the proper spelling in your native language, if so then why did you also use "a stupid American" or is either correct?
March 18, 2011 at 8:58 am
tommyh (3/18/2011)
I was hoping that SQL would fail on the last comma in the create table part. But SQL was just as happy to create a table like that./T
I second this comment...it tripped me up too.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
March 18, 2011 at 9:12 am
THANKS FOR CALLING ME STUPID. YOUR ARROGANCE OR SHOULD I SAY EGOTISM IS APPALING.
As aside, you really should spell check your work before posting or is "stupic" the proper spelling in your native language, if so then why did you also use "a stupid American" or is either correct?
*appalling* 😉
I, too, took some slight offense at Hugo's use of stupid, but I also understand the consequences of being surrounded by a majority that assumes everyone else lives as they do. The arrogance can be breathtaking.
One thing I've often appreciated about this forum versus others I have followed is the level of maturity and accommodation.
Back to the QotD: Anyone come up with a good reason why the trailing comma is allowed? Or why data types aren't reserved words?
Rich
March 18, 2011 at 9:15 am
I was going to get it right, but then saw the '2/13' date and dithered, knowing that the insert would fail on my British system, and then guessed that the questioner was also on a system with the same date format and that it was a cunning 'gotcha'.
Oh well, live and learn.
March 18, 2011 at 9:24 am
bitbucket-25253 (3/18/2011)
THANKS FOR CALLING ME STUPID. YOUR ARROGANCE OR SHOULD I SAY EGOTISM IS APPALLING.
Hmmm. Are you now implying that your use of a non-universal date format was not cause by ignorance, but a deliberate attempt to trick non-Americans in giving the wrong answer? I thought better of you. But in that case, I have to apologize for the word stupid - describing how I feel about deliberately using US-only dates and omittiing the correct answer needs a completely different set of words.
If it was ignorance, not malice, then sorry if my words offended you. I didn't mean to offend. I did mean to place a firm wake-up call to all the people (in my experience almost always Americans) who all too often forget that there are more countries in the world. That kind of ignorance has, in my opinion, no place in the 21st century world.
When I started writing this reply, no less than 10 people had already commented in one way or another on the date format issue. You only responded to me, and in your response you only addressed a word that offended you, and one of my typos. I don't mind if you ignore me, but are you at least planning to address the concerns of those other 9 people?
March 18, 2011 at 10:06 am
Thanks for the question, it is interesting to know that you can have a superfluous comma in a CREATE TABLE statement. (Not sure that is of much value other than what HUGO mentioned for commenting code out.)
Viewing 15 posts - 31 through 45 (of 101 total)
You must be logged in to reply to this topic. Login to reply