CREATE TABLE [dbo].[md_grids]
(
[grd_grid_name] [dbo].[ais_name] NOT NULL,
[grd_rowver] [timestamp] NOT NULL,
[grd_l1] [nvarchar] (64) COLLATE French_CI_AS NOT NULL,
[grd_l2] [nvarchar] (64) COLLATE French_CI_AS NULL,
[grd_l3] [nvarchar] (64) COLLATE French_CI_AS NULL,
[grd_value_table_name] [dbo].[ais_name] NULL,
[grd_value_field_name] [dbo].[ais_name] NULL,
[grd_display_table_name] [dbo].[ais_name] NULL,
[grd_display_field_name] [dbo].[ais_name] NULL,
[grd_sql] [varchar] (1024) COLLATE French_CI_AS NULL,
[grd_columns_fill] [bit] NOT NULL CONSTRAINT [DF__md_grids__grd_columns_fill] DEFAULT ((0)),
[grd_show_required_icon] [bit] NOT NULL CONSTRAINT [DF__md_grids__grd_show_required_icon] DEFAULT ((0)),
[grd_display_combo_expression] [varchar] (150) COLLATE French_CI_AS NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[md_grids] ADD
CONSTRAINT [CK__md_grids_grd_grid_name__string_pk] CHECK ((len(ltrim(rtrim([grd_grid_name])))>(0) AND charindex('*',[grd_grid_name])=(0) AND charindex('%',[grd_grid_name])=(0)))
GO
ALTER TABLE [dbo].[md_grids] ADD CONSTRAINT [PK_md_grids] PRIMARY KEY CLUSTERED  ([grd_grid_name]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[md_grids] ADD CONSTRAINT [FK_md_grids_md_fields_display] FOREIGN KEY ([grd_display_table_name], [grd_display_field_name]) REFERENCES [dbo].[md_fields] ([fld_table_name], [fld_field_name])
GO
ALTER TABLE [dbo].[md_grids] ADD CONSTRAINT [FK_md_grids_md_fields_value] FOREIGN KEY ([grd_value_table_name], [grd_value_field_name]) REFERENCES [dbo].[md_fields] ([fld_table_name], [fld_field_name])
GO
