sql >> Database teknologi >  >> RDS >> Sqlserver

hvordan man får tabellens skemanavn

Brug 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. PHP mysql søg i flere tabeller ved hjælp af et nøgleord

  2. Matcher en gruppe, der måske eksisterer eller ikke

  3. Sådan angives sorteringen i en forespørgsel i SQL Server (T-SQL)

  4. Sammenlign streng i Oracle Case When