Link to home
Start Free TrialLog in
Avatar of waltforbes
waltforbesFlag for Bahamas

asked on

Basic T-SQL Script Failure

Points of My Scenario:

1. I am studying T-SQL as a newbie/novice.

2. I have successfully created three tables as per commands in attached SQL script, CREATE-Tables.txt

3. I attempt to perform a data insert into the Sales table with the following SQL statement: " INSERT Sales SELECT NEWID(),1, 1, 4, '02/01/2012' " - without the quotes (" "), of course! :-)

4. I receive the following error: "Msg 213, Level 16, State 1, Line 1. Column name or number of supplied values does not match table definition."

QUESTION/REQUEST: Please correct the syntax in my T-SQL statement or advise me what I am doing wrongly. Remember that I am a newbie! :-)
CREATE-Tables.txt
SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As an aside, what's the purpose of SaleID being a uniqueidentifier instead of an int with or without an identity?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of waltforbes

ASKER

You guys are so awesome here! You have totally resolved my issue. I am happy & very grateful.
I decided to add another column to the Sales table named 'PurchaseDate' with the data type of datetime.

@Jim Horn: I used the uniqueidentifier data type in the Sales table, just for experimentation with data types. I am studying with CBT Nuggets, and was going along with the lesson. Alas! they supplied bad scripts! It wasn't even in my paradigm that it was possible that their script was wrong - after all, they demonstrated it! Oh well.

Thank goodness for Experts Exchange! I am much grateful.
Ok.  Most places I've seen will use an int identity(1,1) and it's good enough.  That and it's four bytes in size vs. 16-bytes for a GUID, so the GUID takes up four times the memory and would take longer to load.

Thanks for the split, good luck with your learning.  Feel free to ask questions here anytime.
'Hello world' - and hear ye, world: wonderful people live at Experts Exchange! Yaaay! :-D
ThumbsUpEE.PNG