Search
 
SCRIPT & CODE EXAMPLE
 

SQL

Get a list of tables and the primary key

select schema_name(tab.schema_id) as [schema_name], 
    tab.[name] as table_name, 
    pk.[name] as pk_name,
    substring(column_names, 1, len(column_names)-1) as [columns]
from sys.tables tab
    left outer join sys.indexes pk
        on tab.object_id = pk.object_id 
        and pk.is_primary_key = 1
   cross apply (select col.[name] + ', '
                    from sys.index_columns ic
                        inner join sys.columns col
                            on ic.object_id = col.object_id
                            and ic.column_id = col.column_id
                    where ic.object_id = tab.object_id
                        and ic.index_id = pk.index_id
                            order by col.column_id
                            for xml path ('') ) D (column_names)
order by schema_name(tab.schema_id),
    tab.[name]
Comment

PREVIOUS NEXT
Code Example
Sql :: Search In the Database using Text 
Sql :: cara menampilkan user di mysql terminal 
Sql :: many to many flask-sqlalchemy 
Sql :: in in sql 
Sql :: sqlite3 visual table schema 
Sql :: mysql order by rand limit 1 really slow 
Sql :: select multiple tables mysql 
Sql :: MySql Subtract a table from another 
Sql :: Inserting data into different tables at once in oracle sql 
Sql :: SQL Greater than () 
Sql :: insert json file to mssql 
Sql :: mysql varchar length 
Sql :: mysql even numbers 
Sql :: max mysql 
Sql :: sql where multiple values 
Sql :: not equal in mysql query 
Sql :: linq inner join 
Sql :: into in sql 
Sql :: list all functions and procedures in postgres query 
Sql :: postgresql sum 
Sql :: duplicate row mysql 
Sql :: default username and password for oracle 11g 
Sql :: find max number in sql 
Sql :: sql change primary key to composite key 
Sql :: sql server download for windows 10 64 bit 
Sql :: mysql current date between two dates 
Sql :: sql is not null 
Sql :: sql count * vs count 1 
Sql :: table user postgres 
Sql :: postgresql comandos basicos 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =