sql >> Databáze >  >> RDS >> Sqlserver

jak získat název schématu tabulky

Použijte OBJECT_SCHEMA_NAME

SELECT 
  OBJECT_SCHEMA_NAME(f.parent_object_id) AS TableNameSchema, -- this
  OBJECT_NAME(f.parent_object_id) AS TableName,
  COL_NAME(fc.parent_object_id,fc.parent_column_id) AS ColumnName,
  OBJECT_SCHEMA_NAME(f.referenced_object_id) AS ReferenceTableNameSchema,
  OBJECT_NAME (f.referenced_object_id) AS ReferenceTableName,
  COL_NAME(fc.referenced_object_id,fc.referenced_column_id) AS ReferenceColumnName,
  f.name AS ForeignKey
FROM
  sys.foreign_keys AS f
  INNER JOIN sys.foreign_key_columns AS fc ON f.OBJECT_ID = fc.constraint_object_id
  INNER JOIN sys.objects AS o ON o.OBJECT_ID = fc.referenced_object_id


  1. Jak mohu INSERT data do dvou tabulek současně v SQL Server?

  2. Spojení tabulky se sebou samým vs pomocí Group By MySQL

  3. Kdy zvážit Solr

  4. Java - najděte první příčinu výjimky