CREATE TABLE [dbo].[usr_users]
(
[usr_user_code] [dbo].[ais_code_medium] NOT NULL,
[usr_rowver] [timestamp] NOT NULL,
[usr_profil_code] [dbo].[ais_code_short] NOT NULL,
[usr_name] [nvarchar] (64) COLLATE French_CI_AS NOT NULL,
[usr_pwd] [nvarchar] (64) COLLATE French_CI_AS NULL,
[usr_mail] [nvarchar] (64) COLLATE French_CI_AS NULL,
[usr_culture_code] [dbo].[ais_code_short] NOT NULL CONSTRAINT [DF_usr_users_usr_culture] DEFAULT ('l1'),
[usr_idle] [smallint] NULL,
[usr_freeze] [bit] NOT NULL CONSTRAINT [DF__usr_users__usr_freeze] DEFAULT ((0)),
[usr_sys] [bit] NOT NULL CONSTRAINT [DF__usr_users__usr_sys] DEFAULT ((0)),
[usr_date_setup] [date] NOT NULL CONSTRAINT [DF_usr_users_usr_date_setup] DEFAULT (getdate()),
[usr_action_code__fn] [dbo].[ais_code_short] NOT NULL CONSTRAINT [DF_usr_users_usr_action_code__fn] DEFAULT ('A'),
[usr_action_code__fnr] [dbo].[ais_code_short] NOT NULL CONSTRAINT [DF_usr_users_usr_action_code__fnr] DEFAULT ('A'),
[usr_action_code__cs] [dbo].[ais_code_short] NOT NULL CONSTRAINT [DF_usr_users_usr_action_code__fnr1] DEFAULT ('A'),
[usr_action_code__ct] [dbo].[ais_code_short] NOT NULL CONSTRAINT [DF_usr_users_usr_action_code__cs1] DEFAULT ('A'),
[usr_dictionary_code] [dbo].[ais_code_short] NULL,
[usr_introducer_id] [int] NULL,
[usr_modify_protected_fields] [bit] NOT NULL CONSTRAINT [DF__usr_users__usr_modify_protected_fields] DEFAULT ((0)),
[usr_allow_partial_payment] [bit] NOT NULL CONSTRAINT [DF__usr_users__usr_allow_partial_payment] DEFAULT ((0)),
[usr_delegation_allow_invoice_unit_rate] [bit] NOT NULL CONSTRAINT [DF__usr_users__usr_delegation_allow_invoice_unit_rate] DEFAULT ((0))
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[t_usr_users_d] 
   ON  [dbo].[usr_users]
   AFTER DELETE
AS 

BEGIN
	
	SET NOCOUNT ON;

	delete uuo 
	from usr_users_options uuo
	where uuo.usro_user_code in (	select usr_user_code from deleted)
 
END

GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [CK__usr_users_usr_user_code__string_pk] CHECK ((len(ltrim(rtrim([usr_user_code])))>(0) AND charindex('*',[usr_user_code])=(0) AND charindex('%',[usr_user_code])=(0)))
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [PK_usr_users] PRIMARY KEY CLUSTERED  ([usr_user_code]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [FK_usr_users_act_introducers] FOREIGN KEY ([usr_introducer_id]) REFERENCES [dbo].[act_introducers] ([int_actor_id])
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [FK_usr_users_md_cultures] FOREIGN KEY ([usr_culture_code]) REFERENCES [dbo].[md_cultures] ([clt_culture_code]) ON UPDATE CASCADE
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [FK_usr_users_md_dictionaries] FOREIGN KEY ([usr_dictionary_code]) REFERENCES [dbo].[md_dictionaries] ([dict_dictionary_code])
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [FK_usr_users_nm_actions] FOREIGN KEY ([usr_action_code__fn]) REFERENCES [dbo].[nm_actions] ([actn_action_code])
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [FK_usr_users_nm_actions1] FOREIGN KEY ([usr_action_code__fnr]) REFERENCES [dbo].[nm_actions] ([actn_action_code])
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [FK_usr_users_nm_actions2] FOREIGN KEY ([usr_action_code__cs]) REFERENCES [dbo].[nm_actions] ([actn_action_code])
GO
ALTER TABLE [dbo].[usr_users] ADD CONSTRAINT [FK_usr_users_nm_actions3] FOREIGN KEY ([usr_action_code__ct]) REFERENCES [dbo].[nm_actions] ([actn_action_code])
GO
ALTER TABLE [dbo].[usr_users] WITH NOCHECK ADD CONSTRAINT [FK_usr_users_usr_profils] FOREIGN KEY ([usr_profil_code]) REFERENCES [dbo].[usr_profils] ([pr_profil_code])
GO
