USP_AUDIT_AUDITTABLELIST
List names of all Audit tables and whether auditing is enabled or not for that table.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@NAME | nvarchar(255) | IN | |
@ONLYENABLED | bit | IN |
Definition
Copy
CREATE procedure dbo.USP_AUDIT_AUDITTABLELIST
(
@NAME nvarchar(255) = null,
@ONLYENABLED bit = 0
)
with execute as owner
as
set nocount on;
set @NAME = dbo.UFN_SEARCHCRITERIA_GETLIKEPARAMETERVALUE(@NAME, 0, null);
if @ONLYENABLED is null
set @ONLYENABLED = 0;
select
left(AUDITTABLE.TABLE_NAME, len(AUDITTABLE.TABLE_NAME) - 5) 'TABLENAME',
coalesce(dbo.UFN_AUDITENABLED(left(AUDITTABLE.TABLE_NAME, len(AUDITTABLE.TABLE_NAME) - 5)), cast(0 as bit)) 'AUDITENABLED'
from INFORMATION_SCHEMA.TABLES AUDITTABLE
inner join INFORMATION_SCHEMA.TABLES BASETABLE on BASETABLE.TABLE_NAME = left(AUDITTABLE.TABLE_NAME, len(AUDITTABLE.TABLE_NAME) - 5) and BASETABLE.TABLE_TYPE = 'BASE table'
where (AUDITTABLE.TABLE_TYPE = 'BASE table') and (right(AUDITTABLE.TABLE_NAME, 5) = 'AUDIT') and
(object_id(left(AUDITTABLE.TABLE_NAME, (len(AUDITTABLE.TABLE_NAME) - 5))) is not null) and
((@NAME is null) or (AUDITTABLE.TABLE_NAME like @NAME)) and
((@ONLYENABLED = 0) or (coalesce(dbo.UFN_AUDITENABLED(left(AUDITTABLE.TABLE_NAME, len(AUDITTABLE.TABLE_NAME) - 5)), cast(0 as bit)) = 1))
order by TABLENAME;