在SQL Server中,有没有一种方法可以计算临时表(#temptable)中列的数量?
在SQL Server中,有没有一种方法可以计算临时表(#temptable)中列的数量?
SELECT COUNT(*)
FROM tempdb.sys.columns
WHERE object_id = object_id('tempdb..#mytemptable')
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
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 + '%' )
SELECT COUNT(*) FROM temptable
COUNT(*)
将返回行数的计数 - Pratik