我想从使用数据库中返回所有表名,但这只是返回一个字符

declare @contador int

set @contador = 1

while (@contador<=(select count(table_name) from INFORMATION_SCHEMA.TABLES))
begin
declare @tableName varchar
    set @tableName =  (select top 1 * from (select top(@contador) table_name from INFORMATION_SCHEMA.TABLES order by table_name asc) as nombre order by table_name desc)
    print @tableName
    set @contador = @contador + 1
end

输出是s
s
s
s
s
s

最佳答案

declare @tableName varchar(100)

您需要定义@tableName的长度,默认情况下将其设置为1个字符。

10-02 18:59