I have the following code that I compiled that seems to work fine. However, I need to put it in a stored procedure, but I get the following error:
use statement not allowed in procedure, function, or trigger
Does anyone know about work?
CREATE TABLE
(
[TableName] VARCHAR(128),
[RowCount] INT
)
CREATE TABLE
(
[TableName] VARCHAR(128),
[RowCount] INT
)
use Database1
GO
INSERT INTO
(
[TableName],
[RowCount]
)
EXEC sp_MSforeachtable
'SELECT ''?''
[TableName],
COUNT(*) [RowCount]
FROM ?'
use Database2
GO
INSERT INTO
(
[TableName],
[RowCount]
)
EXEC sp_MSforeachtable
'SELECT ''?''
[TableName],
COUNT(*) [RowCount]
FROM ?'
source
share