Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Error while storing results of sp_spaceused in a n

Author  Topic 

anjaliv
Starting Member

10 Posts

Posted - 2011-07-07 : 13:11:47
Hi All,

I am getting the following error when run the below script.
"Insert Error: Column name or number of supplied values does not match table definition."

DECLARE name_cur CURSOR FOR SELECT DISTINCT db_name, obj_name from table1
OPEN name_cur
CREATE TABLE [dbo].[Table_MetaData](
[name] [nvarchar](50)
[rows] [int]
[reserved] [varchar](50)
[data] [varchar](50)
[index_sze] [varchar](50)
[unused] [varchar](50)
)
FETCH name_cur INTO @db_name, @table_name
WHILE @@Fetch_Status = 0
BEGIN

SET @sql = @db_name+'..sp_spaceused '+ '"'+@table_name+'"'
insert into [dbo].[Table_MetaData]
EXEC (@sql)
FETCH name_cur INTO @db_name, @table_name
END

Thank you!

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-07-07 : 13:16:14
Here's another version that doesn't require a cursor:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=53843
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-07-07 : 13:23:47
You didn't declare variables, or put commas after column definitions in your DDL either.
Go to Top of Page

anjaliv
Starting Member

10 Posts

Posted - 2011-07-07 : 14:27:42
I forgot to post it here, but I have declared variables and commas. if I parse the script, there is no error. But when I run it it gives an error " Insert Error: Column name or number of supplied values does not match table definition."
I am not sure what is wrong with the query.
Go to Top of Page
   

- Advertisement -