有没有办法计算 sql server 中临时(#temptable)表中的列数?
问问题
12857 次
4 回答
11
SELECT COUNT(*)
FROM tempdb.sys.columns
WHERE object_id = object_id('tempdb..#mytemptable')
于 2013-09-12T10:02:19.440 回答
1
查询以获取指定表的列数
SELECT Count(*) as cnt into #TempTable FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'TableName'
查询以获取指定表的列名
SELECT COLUMN_NAME into #TempTable FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'TableName'
查询以获取#TempTable 的列数
SELECT COUNT(*) as Cnt FROM tempdb.sys.columns WHERE object_id = object_id('tempdb..#TempTable')
DROP table #TempTable
于 2013-09-12T10:07:22.553 回答
0
您可以使用此查询:
Declare @TableName NVarChar(150)
Declare @ColumnName NVarChar(150)
Set @TableName = ''
Set @ColumnName = ''
SELECT
t.name AS table_name,
SCHEMA_NAME(schema_id) AS schema_name,
c.name AS column_name
FROM sys.tables AS t
INNER JOIN sys.columns As C ON t.OBJECT_ID = c.OBJECT_ID
Where
( T.name Like '%' + @TableName + '%' )
And
( C.name Like '%' + @ColumnName + '%' )
SELECT
COUNT(C.Name) Count_Of_Columns,
COUNT(Distinct T.Name) Count_Of_Tables
FROM sys.tables AS t
INNER JOIN sys.columns As C ON t.OBJECT_ID = c.OBJECT_ID
Where
( T.name Like '%' + @TableName + '%' )
And
( C.name Like '%' + @ColumnName + '%' )
于 2015-04-25T05:50:22.557 回答
-2
SELECT COUNT(*) FROM temptable
于 2013-09-12T10:02:56.883 回答