SCHEMA PREVIEW
ELE_RES_USERS
Xem trước DDL trước khi tạo hoặc bổ sung cột an toàn trên SQL Server.
SQL Server DDL
Chỉ tự động tạo schema/table/index và thêm cột nullable còn thiếu.
IF SCHEMA_ID(N'stg') IS NULL EXEC(N'CREATE SCHEMA [stg]');
IF SCHEMA_ID(N'ods') IS NULL EXEC(N'CREATE SCHEMA [ods]');
IF SCHEMA_ID(N'hist') IS NULL EXEC(N'CREATE SCHEMA [hist]');
IF OBJECT_ID(N'stg.J17_ele_res_users', N'U') IS NULL
BEGIN
CREATE TABLE [stg].[J17_ele_res_users]
(
[id] int NULL,
[company_id] int NULL,
[partner_id] int NULL,
[active] bit NULL,
[create_date] datetime2(6) NULL,
[login] nvarchar(max) NULL,
[password] nvarchar(max) NULL,
[action_id] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[signature] nvarchar(max) NULL,
[share] bit NULL,
[write_date] datetime2(6) NULL,
[totp_secret] nvarchar(max) NULL,
[tour_enabled] bit NULL,
[notification_type] nvarchar(max) NULL,
[odoobot_state] nvarchar(max) NULL,
[odoobot_failed] bit NULL,
[sale_team_id] int NULL,
[slp_code] nvarchar(max) NULL,
[business_area] nvarchar(max) NULL,
[branch] nvarchar(max) NULL,
[dialog_size] nvarchar(max) NULL,
[sidebar_type] nvarchar(max) NULL,
[chatter_position] nvarchar(max) NULL,
[website_id] int NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[sync_row_hash] varbinary(32) NOT NULL,
[sync_is_deleted] bit NOT NULL,
[sync_created_at] datetime2(7) NOT NULL,
[sync_updated_at] datetime2(7) NOT NULL
);
END;
IF OBJECT_ID(N'ods.ele_res_users', N'U') IS NULL
BEGIN
CREATE TABLE [ods].[ele_res_users]
(
[id] int NOT NULL,
[company_id] int NOT NULL,
[partner_id] int NOT NULL,
[active] bit NULL,
[create_date] datetime2(6) NULL,
[login] nvarchar(max) NOT NULL,
[password] nvarchar(max) NULL,
[action_id] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[signature] nvarchar(max) NULL,
[share] bit NULL,
[write_date] datetime2(6) NULL,
[totp_secret] nvarchar(max) NULL,
[tour_enabled] bit NULL,
[notification_type] nvarchar(max) NOT NULL,
[odoobot_state] nvarchar(max) NULL,
[odoobot_failed] bit NULL,
[sale_team_id] int NULL,
[slp_code] nvarchar(max) NULL,
[business_area] nvarchar(max) NULL,
[branch] nvarchar(max) NULL,
[dialog_size] nvarchar(max) NOT NULL,
[sidebar_type] nvarchar(max) NOT NULL,
[chatter_position] nvarchar(max) NOT NULL,
[website_id] int NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[sync_row_hash] varbinary(32) NOT NULL,
[sync_is_deleted] bit NOT NULL CONSTRAINT [DF_ele_res_users_IsDeleted] DEFAULT (0),
[sync_created_at] datetime2(7) NOT NULL,
[sync_updated_at] datetime2(7) NOT NULL,
CONSTRAINT [PK_ele_res_users] PRIMARY KEY ([sync_source_id], [id])
);
END;
IF OBJECT_ID(N'hist.J17_ele_res_users_History', N'U') IS NULL
BEGIN
CREATE TABLE [hist].[J17_ele_res_users_History]
(
[history_id] bigint IDENTITY(1,1) NOT NULL PRIMARY KEY,
[source_record_id] nvarchar(450) NOT NULL,
[id] int NULL,
[company_id] int NULL,
[partner_id] int NULL,
[active] bit NULL,
[create_date] datetime2(6) NULL,
[login] nvarchar(max) NULL,
[password] nvarchar(max) NULL,
[action_id] int NULL,
[create_uid] int NULL,
[write_uid] int NULL,
[signature] nvarchar(max) NULL,
[share] bit NULL,
[write_date] datetime2(6) NULL,
[totp_secret] nvarchar(max) NULL,
[tour_enabled] bit NULL,
[notification_type] nvarchar(max) NULL,
[odoobot_state] nvarchar(max) NULL,
[odoobot_failed] bit NULL,
[sale_team_id] int NULL,
[slp_code] nvarchar(max) NULL,
[business_area] nvarchar(max) NULL,
[branch] nvarchar(max) NULL,
[dialog_size] nvarchar(max) NULL,
[sidebar_type] nvarchar(max) NULL,
[chatter_position] nvarchar(max) NULL,
[website_id] int NULL,
[sync_source_id] int NOT NULL,
[sync_job_id] int NOT NULL,
[sync_run_id] bigint NOT NULL,
[valid_from] datetime2(7) NOT NULL,
[valid_to] datetime2(7) NULL,
[is_current] bit NOT NULL,
[row_hash] varbinary(32) NOT NULL,
[source_updated_at] datetimeoffset(7) NOT NULL,
[sync_is_deleted] bit NOT NULL
);
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'id') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [id] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'id') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [id] int NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'company_id') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'company_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'company_id') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [company_id] int NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'partner_id') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [partner_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'partner_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [partner_id] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'partner_id') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [partner_id] int NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'active') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [active] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'active') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [active] bit NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'active') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [active] bit NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'create_date') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'create_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'create_date') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [create_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'login') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [login] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'login') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [login] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'login') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [login] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'password') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [password] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'password') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [password] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'password') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [password] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'action_id') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [action_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'action_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [action_id] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'action_id') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [action_id] int NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'create_uid') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'create_uid') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'create_uid') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [create_uid] int NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'write_uid') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'write_uid') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'write_uid') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [write_uid] int NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'signature') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [signature] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'signature') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [signature] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'signature') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [signature] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'share') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [share] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'share') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [share] bit NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'share') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [share] bit NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'write_date') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'write_date') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'write_date') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [write_date] datetime2(6) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'totp_secret') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [totp_secret] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'totp_secret') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [totp_secret] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'totp_secret') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [totp_secret] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'tour_enabled') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [tour_enabled] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'tour_enabled') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [tour_enabled] bit NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'tour_enabled') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [tour_enabled] bit NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'notification_type') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [notification_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'notification_type') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [notification_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'notification_type') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [notification_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'odoobot_state') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [odoobot_state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'odoobot_state') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [odoobot_state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'odoobot_state') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [odoobot_state] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'odoobot_failed') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [odoobot_failed] bit NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'odoobot_failed') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [odoobot_failed] bit NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'odoobot_failed') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [odoobot_failed] bit NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'sale_team_id') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [sale_team_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'sale_team_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [sale_team_id] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'sale_team_id') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [sale_team_id] int NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'slp_code') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [slp_code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'slp_code') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [slp_code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'slp_code') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [slp_code] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'business_area') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [business_area] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'business_area') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [business_area] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'business_area') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [business_area] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'branch') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [branch] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'branch') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [branch] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'branch') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [branch] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'dialog_size') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [dialog_size] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'dialog_size') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [dialog_size] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'dialog_size') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [dialog_size] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'sidebar_type') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [sidebar_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'sidebar_type') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [sidebar_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'sidebar_type') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [sidebar_type] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'chatter_position') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [chatter_position] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'chatter_position') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [chatter_position] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'chatter_position') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [chatter_position] nvarchar(max) NULL;
END;
IF COL_LENGTH(N'stg.J17_ele_res_users', N'website_id') IS NULL
BEGIN
ALTER TABLE [stg].[J17_ele_res_users] ADD [website_id] int NULL;
END;
IF COL_LENGTH(N'ods.ele_res_users', N'website_id') IS NULL
BEGIN
ALTER TABLE [ods].[ele_res_users] ADD [website_id] int NULL;
END;
IF COL_LENGTH(N'hist.J17_ele_res_users_History', N'website_id') IS NULL
BEGIN
ALTER TABLE [hist].[J17_ele_res_users_History] ADD [website_id] int NULL;
END;
IF NOT EXISTS
(
SELECT 1
FROM sys.indexes AS indexes
INNER JOIN sys.index_columns AS first_column
ON first_column.[object_id] = indexes.[object_id]
AND first_column.[index_id] = indexes.[index_id]
AND first_column.[key_ordinal] = 1
INNER JOIN sys.columns AS first_column_name
ON first_column_name.[object_id] = first_column.[object_id]
AND first_column_name.[column_id] = first_column.[column_id]
INNER JOIN sys.index_columns AS second_column
ON second_column.[object_id] = indexes.[object_id]
AND second_column.[index_id] = indexes.[index_id]
AND second_column.[key_ordinal] = 2
INNER JOIN sys.columns AS second_column_name
ON second_column_name.[object_id] = second_column.[object_id]
AND second_column_name.[column_id] = second_column.[column_id]
WHERE indexes.[object_id] = OBJECT_ID(N'ods.ele_res_users')
AND first_column_name.[name] = N'sync_source_id'
AND second_column_name.[name] = N'id'
)
CREATE INDEX [IX_ele_res_users_SyncSource_Key] ON [ods].[ele_res_users] ([sync_source_id], [id]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'ods.ele_res_users') AND name = N'IX_ele_res_users_UpdatedAt_Id')
CREATE INDEX [IX_ele_res_users_UpdatedAt_Id] ON [ods].[ele_res_users] ([write_date], [id]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'ods.ele_res_users') AND name = N'IX_ele_res_users_IsDeleted')
CREATE INDEX [IX_ele_res_users_IsDeleted] ON [ods].[ele_res_users] ([sync_is_deleted]);
IF NOT EXISTS (SELECT 1 FROM sys.indexes WHERE object_id = OBJECT_ID(N'hist.J17_ele_res_users_History') AND name = N'IX_J17_ele_res_users_History_Record')
CREATE INDEX [IX_J17_ele_res_users_History_Record] ON [hist].[J17_ele_res_users_History] ([sync_source_id], [source_record_id], [is_current]);