Sqlserver
 sql >> Teknologi Basis Data >  >> RDS >> Sqlserver

cara mendapatkan nama skema tabel

Gunakan 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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Saya mengganti nama kolom saya untuk memasukkan nama tabel. Mengapa saya tidak bisa mengganti namanya lagi?

  2. Cara menghasilkan rentang tanggal di SQL Server

  3. Cara Menginstal SQL Server di Linux

  4. Tahu-Cara Mengembalikan Catatan yang Dihapus di SQL Server

  5. Mendapatkan pengidentifikasi basis data unik untuk SQL Server 2005 dan yang lebih baru