Display user tables using sqlcmd

1

I have the following statement to connect to the database:

sqlcmd -S tcp:ip -U usuario -P password

How can I know which tables are created by that user and their structure?

I tried with

select name from sysobjects .. 

But I have not had the desired result.

    
asked by jehs 13.09.2018 в 23:01
source

1 answer

1

What you can know is who is the owner of the table, not necessarily who created it. Suppose that the user is dbo , to get the names of the tables and the structure of each, you can lean on the views:

Example, filtering by Owner dbo :

SELECT  T.TABLE_CATALOG,
    T.TABLE_SCHEMA,
    T.TABLE_NAME,
    C.ORDINAL_POSITION, 
    C.COLUMN_NAME, 
    C.DATA_TYPE, 
    C.CHARACTER_MAXIMUM_LENGTH, 
    C.IS_NULLABLE, 
    C.NUMERIC_PRECISION,
    C.NUMERIC_SCALE
    FROM INFORMATION_SCHEMA.TABLES T
    INNER JOIN INFORMATION_SCHEMA.COLUMNS C
        ON C.TABLE_CATALOG = T.TABLE_CATALOG
        AND C.TABLE_SCHEMA = T.TABLE_SCHEMA
        AND C.TABLE_NAME = T.TABLE_NAME
    WHERE T.TABLE_SCHEMA = 'dbo'
    ORDER BY T.TABLE_CATALOG,
        T.TABLE_SCHEMA,
        T.TABLE_NAME,
        C.ORDINAL_POSITION

Here a fiddle

    
answered by 14.09.2018 в 15:29