(Select d.name As 表名, a.colid As '序号', a.name As '列名',
Case When b.name In ('varchar', 'nvarchar', 'varbinary', 'decimal', 'numeric') Then
b.name + '(' + Cast(IsNull(Case b.name When 'int' Then Null When 'text' Then Null When 'datetime' Then Null Else ColumnProperty(a.id, a.name, 'PRECISION')End, '') As Varchar(5))
+ Case When b.name In ('decimal', 'numeric') Then ',' + Cast(ColumnProperty(a.id, a.name, 'Scale') As Varchar(5))Else '' End + ')' Else b.name End As '数据类型', Case ix.is_primary_key When 1 Then '√' Else '' End As '主键',
Case ix.is_unique When 1 Then '√' Else '' End As '唯一标识', Case When ix.name Is Null Then '' Else '√' End As '索引', (Case When a.isnullable = 1 Then '√' Else '' End) As '允许空',
Case When e.text Is Null Then ''
When Left(e.text, 2) = '((' Then Substring(e.text, 3, Len(e.text) - 4)
When Left(e.text, 1) = '(' Then Substring(e.text, 2, Len(e.text) - 2)Else e.text End As '默认值', Case ix.is_primary_key When 1 Then '自增主键' Else IsNull(f.value, '')End As '说明'
From sys.syscolumns a
Left Join sys.types b On a.xtype = b.user_type_id
Inner Join sys.sysobjects d On a.id = d.id And d.xtype = 'U' And d.name != 'dtproperties'
Left Join sys.syscomments e On a.cdefault = e.id
Left Join sys.extended_properties f On f.major_id = d.id And f.minor_id = a.colid
Left Join sys.extended_properties ft On ft.major_id = d.id And ft.minor_id = 0
Left Join sys.index_columns ixc On ixc.object_id = a.id And ixc.column_id = a.colid
Left Join sys.indexes ix On ix.object_id = ixc.object_id And ix.index_id = ixc.index_id) t
varsql=@" Select Distinct a.ID As ModelID, a.Name As ModelName, b.BusinessObject, b.WinForm, IsNull(b.Param, '') As Param, c.ModuleId, Case When c.ModuleId Is Null Then 0 Else 1 End As IsSelect
From dbo.SysBusinessModel a
Left Join dbo.SysFunction b On b.ModelID = a.ID And b.Name In ('Add') And Len(b.WinForm) > 1
Left Join dbo.Sys_ModuleBusinessModel c On c.ModelId = a.ID
Where Not Exists (Select 1 From SysBusinessModel Where PrevID = a.ID)
(Select d.name As 表名, a.colid As '序号', a.name As '列名',
Case When b.name In ('varchar', 'nvarchar', 'varbinary', 'decimal', 'numeric') Then
b.name + '(' + Cast(IsNull(Case b.name When 'int' Then Null When 'text' Then Null When 'datetime' Then Null Else ColumnProperty(a.id, a.name, 'PRECISION')End, '') As Varchar(5))
+ Case When b.name In ('decimal', 'numeric') Then ',' + Cast(ColumnProperty(a.id, a.name, 'Scale') As Varchar(5))Else '' End + ')' Else b.name End As '数据类型', Case ix.is_primary_key When 1 Then '√' Else '' End As '主键',
Case ix.is_unique When 1 Then '√' Else '' End As '唯一标识', Case When ix.name Is Null Then '' Else '√' End As '索引', (Case When a.isnullable = 1 Then '√' Else '' End) As '允许空',
Case When e.text Is Null Then ''
When Left(e.text, 2) = '((' Then Substring(e.text, 3, Len(e.text) - 4)
When Left(e.text, 1) = '(' Then Substring(e.text, 2, Len(e.text) - 2)Else e.text End As '默认值', Case ix.is_primary_key When 1 Then '自增主键' Else IsNull(f.value, '')End As '说明'
From sys.syscolumns a
Left Join sys.types b On a.xtype = b.user_type_id
Inner Join sys.sysobjects d On a.id = d.id And d.xtype = 'U' And d.name != 'dtproperties'
Left Join sys.syscomments e On a.cdefault = e.id
Left Join sys.extended_properties f On f.major_id = d.id And f.minor_id = a.colid
Left Join sys.extended_properties ft On ft.major_id = d.id And ft.minor_id = 0
Left Join sys.index_columns ixc On ixc.object_id = a.id And ixc.column_id = a.colid
Left Join sys.indexes ix On ix.object_id = ixc.object_id And ix.index_id = ixc.index_id) t
varsql=@" Select Distinct a.ID As ModelID, a.Name As ModelName, b.BusinessObject, b.WinForm, IsNull(b.Param, '') As Param, c.ModuleId, Case When c.ModuleId Is Null Then 0 Else 1 End As IsSelect
From dbo.SysBusinessModel a
Left Join dbo.SysFunction b On b.ModelID = a.ID And b.Name In ('Add') And Len(b.WinForm) > 1
Left Join dbo.Sys_ModuleBusinessModel c On c.ModelId = a.ID
Where Not Exists (Select 1 From SysBusinessModel Where PrevID = a.ID)