if exists (select * 
from INFORMATION_SCHEMA.VIEWS
where table_name = 'T_SECURITY_AUDIT')
begin
	DROP VIEW [VCLib].[T_SECURITY_AUDIT]

	CREATE TABLE [VCLib].[T_SECURITY_AUDIT](
		[SecurityAuditID] [uniqueidentifier] NOT NULL,
		[ClientSessionId] [uniqueidentifier] NOT NULL,
		[EventDateTime] [datetime] NOT NULL,
		[UserName] [varchar](255) NOT NULL,
	 CONSTRAINT [PK_T_SECURITY_AUDIT] PRIMARY KEY CLUSTERED 
	(
		[SecurityAuditID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
	) ON [PRIMARY]
end
if exists (select * 
from INFORMATION_SCHEMA.VIEWS
where table_name = 'T_SECURITY_AUDIT_CHANGESET')
BEGIN
	DROP VIEW [VCLib].[T_SECURITY_AUDIT_CHANGESET]

	CREATE TABLE [VCLib].[T_SECURITY_AUDIT_CHANGESET](
		[SecurityAuditChangesetID] [uniqueidentifier] NOT NULL,
		[SecurityAudit] [uniqueidentifier] NOT NULL,
		[TargetType] [int] NOT NULL,
		[ObjectName] [varchar](255) NOT NULL,
		[ActionType] [int] NOT NULL,
		[Descr] [varchar](max) NULL,
		[TargetName] [varchar](255) NOT NULL,
		[EventObject] [int] NOT NULL,
	 CONSTRAINT [PK_T_SECURITY_AUDIT_CHANGESET] PRIMARY KEY CLUSTERED 
	(
		[SecurityAuditChangesetID] ASC
	)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
	) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


	ALTER TABLE [VCLib].[T_SECURITY_AUDIT_CHANGESET]  WITH CHECK ADD  CONSTRAINT [FK_T_SECURITY_AUDIT_T_SECURITY_AUDIT_CHANGESET_SECURITYAUDIT] FOREIGN KEY([SecurityAudit])
	REFERENCES [VCLib].[T_SECURITY_AUDIT] ([SecurityAuditID])

	ALTER TABLE [VCLib].[T_SECURITY_AUDIT_CHANGESET] CHECK CONSTRAINT [FK_T_SECURITY_AUDIT_T_SECURITY_AUDIT_CHANGESET_SECURITYAUDIT]
end
