|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 9:12 AM
Points: 6,370,
Visits: 8,235
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Yesterday @ 1:02 AM
Points: 1,277,
Visits: 1,609
|
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 6:12 AM
Points: 2,526,
Visits: 3,620
|
|
I think the question is very good as well, but I am not sure if the answer is correct. I chose Error: "Column name or number of supplied values does not match table definition." for the following reason:
It may not be defined into which table the data is inserted, but the error seems to be raised all the time.
CREATE TABLE #Tables (tablename sysname, rowcnt int, nullable varchar) GO
CREATE PROCEDURE #Proc AS CREATE TABLE #t (a int NOT NULL ) INSERT #t SELECT 1 UNION SELECT 2 -- Insert two rows -- Check which tables we inserted rows into INSERT #Tables SELECT O.name, P.row_count, (SELECT is_nullable FROM sys.columns WHERE name = 'a' AND object_id = O.object_id) from sys.objects O, sys.dm_db_partition_stats P WHERE O.name LIKE '#t\_%' ESCAPE ('\') AND O.object_id = P.object_id GO
GO CREATE TABLE #t (a int NULL) GO INSERT #t SELECT 1 -- Insert one row EXEC #Proc GO
SELECT * FROM #Tables
DROP TABLE #t DROP TABLE #Tables DROP PROCEDURE #Proc GO
In the above code example, you will see that most of the time, 1 row is inserted into the table with the nullable column, and two rows into the other one. Occationally you see that the two are exchanged and this is the "not defined" portion. If you exchange the two insert statements, the above rules are also switched (most of the time 2 rows are inserted into the nullable collumn and only some times vice versa).
Now to the error portion. If you add another column (e.g. b sysname) to one of the CREATE TABLE statements, you will get the column list error message. This error is raised all the time, and also when you switch the table to which you add this extra column. To me this is a strong indication that this error is not "undefined".
Pls let me know your thoughts
Best Regards,
Chris Büttner
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Monday, September 10, 2012 7:49 AM
Points: 49,
Visits: 10
|
|
| I typed the code into my SSMS as I wasn't sure of the answer, and I definitely got the error complaining about the number of columns. I could be doing something wrong? I have SQL 2008 developer edition.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 5:28 AM
Points: 2,659,
Visits: 720
|
|
Excellent question!
I got it wrong on the strength of some tests I ran that gave me the 'Column name or number of supplied values does not match table definition.' error. I failed at scrolling far enough in BOL.
The important bit to take home is that temporary tables and nested stored procedures is a recipe for confusion. I vaguely remember being bitten by this in the mid 90's.
Just because you're right doesn't mean everybody else is wrong.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Today @ 6:30 AM
Points: 3,192,
Visits: 4,151
|
|
Christian Buettner-167247 (12/16/2010) This error is raised all the time, and also when you switch the table to which you add this extra column. To me this is a strong indication that this error is not "undefined".
Pls let me know your thoughts I think you're right. The BOL article clearly states:
However, for modifications to resolve to the table that was created in the nested procedure, the table must have the same structure, with the same column names, as the table created in the calling procedure. So, if the tables have the same name but different structure, any inserts, updates, and deletes will fail with an error.
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Today @ 12:56 AM
Points: 1,972,
Visits: 1,822
|
|
The QOtD asks for what is the output of a specific script and this generates this error: Insert Error: Column name or number of supplied values does not match table definition. and not all possible similar script that COULD generate another kind of error. I want back my points.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Thursday, February 21, 2013 6:30 AM
Points: 562,
Visits: 1,404
|
|
hmm, I get
Msg 213, Level 16, State 1, Procedure Proc2, Line 4 Column name or number of supplied values does not match table definition
SQL 2008 Win 2008 R2
------------------------------------------------------------------------- Normal chaos will be resumed as soon as possible.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 7:27 AM
Points: 1,259,
Visits: 4,260
|
|
| Can I just point out that the code is not SQL 2000 compatible, despite what it says at the top, because of the use of ROW_NUMBER()?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Wednesday, May 23, 2012 6:47 AM
Points: 15,
Visits: 134
|
|
The real error that is displayed is "Incorrect syntax" because there is a non-matching closing parenthesis in the select statement in dbo.Proc1
|
|
|
|