CREATE TABLE [dbo].[md_grids_summaries]
(
[grds_grid_name] [dbo].[ais_name] NOT NULL,
[grds_table_name] [dbo].[ais_name] NOT NULL,
[grds_field_name] [dbo].[ais_name] NOT NULL,
[grds_position_code] [dbo].[ais_code_short] NOT NULL,
[grds_function_code] [dbo].[ais_code_short] NOT NULL,
[grds_l1] [nvarchar] (64) COLLATE French_CI_AS NULL,
[grds_l2] [nvarchar] (64) COLLATE French_CI_AS NULL,
[grds_l3] [nvarchar] (64) COLLATE French_CI_AS NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[md_grids_summaries] ADD
CONSTRAINT [FK_md_grids_summaries_md_grids_summaries_functions] FOREIGN KEY ([grds_function_code]) REFERENCES [dbo].[md_grids_summaries_functions] ([gsf_function_code]) ON UPDATE CASCADE
ALTER TABLE [dbo].[md_grids_summaries] ADD
CONSTRAINT [FK_md_grids_summaries_md_grids_fields] FOREIGN KEY ([grds_grid_name], [grds_table_name], [grds_field_name]) REFERENCES [dbo].[md_grids_fields] ([grdf_grid_name], [grdf_table_name], [grdf_field_name]) ON UPDATE CASCADE
ALTER TABLE [dbo].[md_grids_summaries] ADD
CONSTRAINT [FK_md_grids_summaries_md_grids_summaries_positions] FOREIGN KEY ([grds_position_code]) REFERENCES [dbo].[md_grids_summaries_positions] ([gsp_position_code]) ON UPDATE CASCADE
GO

ALTER TABLE [dbo].[md_grids_summaries] ADD CONSTRAINT [PK_md_grids_summaries] PRIMARY KEY CLUSTERED  ([grds_grid_name], [grds_table_name], [grds_field_name]) ON [PRIMARY]
GO
