@H_404_1@我试图通过执行以下存储过程来确定表的行长度(以字节为单位):
CREATE TABLE #tmp ( [ID] int,Column_name varchar(640),Type varchar(640),Computed varchar(640),Length int,Prec int,Scale int,Nullable varchar(640),TrimTrailingBlanks varchar(640),FixedLenNullInSource varchar(640),Collation varchar(256) ) INSERT INTO #tmp exec sp_help MyTable SELECT SUM(Length) FROM #tmp DROP TABLE #tmp
问题是我不知道’sp_help’返回的表的表定义(数据类型等).
我收到以下错误:
Insert Error: Column name or number of supplied values does not match table definition.
查看sp_help存储过程并没有给我任何线索.
插入sp_help结果的正确CREATE TABLE语句是什么?
解决方法
怎么这样做呢?
CREATE TABLE tblShowContig ( ObjectName CHAR (255),ObjectId INT,IndexName CHAR (255),IndexId INT,Lvl INT,CountPages INT,CountRows INT,MinRecSize INT,MaxRecSize INT,AvgRecSize INT,ForRecCount INT,Extents INT,ExtentSwitches INT,AvgFreeBytes INT,AvgPageDensity INT,ScanDensity DECIMAL,BestCount INT,ActualCount INT,LogicalFrag DECIMAL,ExtentFrag DECIMAL ) GO INSERT tblShowContig EXEC ('DBCC SHOWCONTIG WITH TABLERESULTS') GO SELECT * from tblShowContig WHERE ObjectName = 'MyTable' GO