Script problem with Transact-SQL

I want to return all table names from the usage database, but that just returns a char

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

output s s s s s s

+5
source share
5 answers
declare @tableName varchar(100)

You need to determine the length of @tableName, by default it is set to 1 character.

+3
source

to try  declare @tableName varchar(100)

+1
source

-, . . , , , .

+1

declare @tableName varchar , varchar(50)

+1

T-SQL SYSNAME , :

sysname , , . sysname . SQL Server. sysname nvarchar (128), , sysname NOT NULL. SQL Server, sysname varchar (30).

, :

DECLARE @tableName SYSNAME;

VARCHAR(100), , , 100 .

SQL Server :

  • :

    • , Unicode 3.2. a z, A Z, .

    • (_), (@) (#).

    • SQL Server. , at . , . , (##) - . , .

    • Transact-SQL , double (@@). , , @@.

  • :

    • , Unicode 3.2.

    • .

    • at, ($), .

  • Transact-SQL. SQL Server .

  • .

  • .

. .

+1

All Articles