如何在程序中查找或写入表格?

时间:2015-11-23 09:57:18

标签: sql sql-server tsql

我有一张名为' abc_tbl'我想知道它是在正在使用该表的100个程序的列表中读取(SELECT)还是写入(INSERT,UPDATE,DELETE)。

2 个答案:

答案 0 :(得分:1)

您可以使用information_schema.routines查找引用您的表abc_tbl的过程。

SQL_DATA_ACCESS列将返回以下值之一:

  1. NONE
  2. 包含
  3. READS
  4. MODIFIES
  5. Link to MSDN documentation

    SELECT *
    FROM information_schema.routines ISR
    WHERE CHARINDEX('<your_schema_name>.abc_tbl', ISR.ROUTINE_DEFINITION) > 0
    GO
    

答案 1 :(得分:0)

试试这个

SELECT DISTINCT o.name AS ObjectName,
CASE o.xtype
WHEN 'C' THEN 'CHECK constraint'
WHEN 'D' THEN 'Default or DEFAULT constraint'
WHEN 'F' THEN  'FOREIGN KEY constraint'
WHEN 'FN' THEN 'Scalar function'
WHEN 'IF' THEN 'In-lined table-function'
WHEN 'K' THEN 'PRIMARY KEY or UNIQUE constraint'
WHEN 'L' THEN 'Log'
WHEN 'P' THEN 'Stored procedure'
WHEN 'R' THEN 'Rule'
WHEN 'RF' THEN 'Replication filter stored procedure'
WHEN 'S' THEN 'System table'
WHEN 'TF' THEN 'Table function'
WHEN 'TR' THEN 'Trigger'
WHEN 'U' THEN 'User table'
WHEN 'V' THEN 'View'
WHEN 'X' THEN 'Extended stored procedure'
ELSE o.xtype
END AS ObjectType,
ISNULL( p.Name, '[db]') AS Location
FROM syscomments c
INNER JOIN sysobjects o ON c.id=o.id
LEFT JOIN sysobjects p ON o.Parent_obj=p.id
WHERE c.text LIKE '%table_name%'
ORDER BY Location, ObjectName