SQL Server表自动生成C# Struct结构体语句
--SQL Server表自动生成C# Struct结构体语句
Declare @MyTable varchar(100) --数据库表:'SpeBonus_Set'
Set @MyTable = 'SpeBonus_Set'
SELECT
'public ' +
case when b.name='int' then 'int'
when b.name='tinyint' then 'short'
when b.name='bit' then 'byte'
when b.name='image' then 'byte[]'
when b.name='datetime' then 'string'
when b.name='smalldatetime' then 'string'
when b.name='uniqueidentifier' then 'string'
when b.name='char' then 'char'
when b.name='money' then 'decimal'
else 'string' end
+ ' m_' + (a.name) + ';' 定义变量,
b.name 字段类型, a.isnullable
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sysproperties g on a.id=g.id AND a.colid = g.smallid
where d.name=@MyTable
order by a.id,a.colorder
--Declare @MyTable varchar(100) --数据库表:News
--Set @MyTable = 'SpeBonus_Set'
SELECT
'm_' + (a.name) + ' = ' +
case when b.name='int' then '-1'
when b.name='tinyint' then '0'
when b.name='bit' then 'null'
when b.name='image' then 'null'
when b.name='datetime' then '""'
when b.name='smalldatetime' then '""'
when b.name='uniqueidentifier' then '""'
when b.name='char' then ''''''
when b.name='money' then '0.0'
else '""' end
+ ';' 初始化值,
b.name 字段类型, a.isnullable
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sysproperties g on a.id=g.id AND a.colid = g.smallid
where d.name=@MyTable
order by a.id,a.colorder
Declare @MyTable varchar(100) --数据库表:'SpeBonus_Set'
Set @MyTable = 'SpeBonus_Set'
SELECT
'public ' +
case when b.name='int' then 'int'
when b.name='tinyint' then 'short'
when b.name='bit' then 'byte'
when b.name='image' then 'byte[]'
when b.name='datetime' then 'string'
when b.name='smalldatetime' then 'string'
when b.name='uniqueidentifier' then 'string'
when b.name='char' then 'char'
when b.name='money' then 'decimal'
else 'string' end
+ ' m_' + (a.name) + ';' 定义变量,
b.name 字段类型, a.isnullable
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sysproperties g on a.id=g.id AND a.colid = g.smallid
where d.name=@MyTable
order by a.id,a.colorder
--Declare @MyTable varchar(100) --数据库表:News
--Set @MyTable = 'SpeBonus_Set'
SELECT
'm_' + (a.name) + ' = ' +
case when b.name='int' then '-1'
when b.name='tinyint' then '0'
when b.name='bit' then 'null'
when b.name='image' then 'null'
when b.name='datetime' then '""'
when b.name='smalldatetime' then '""'
when b.name='uniqueidentifier' then '""'
when b.name='char' then ''''''
when b.name='money' then '0.0'
else '""' end
+ ';' 初始化值,
b.name 字段类型, a.isnullable
FROM syscolumns a
left join systypes b on a.xtype=b.xusertype
inner join sysobjects d on a.id=d.id and d.xtype='U' and d.name<>'dtproperties'
left join syscomments e on a.cdefault=e.id
left join sysproperties g on a.id=g.id AND a.colid = g.smallid
where d.name=@MyTable
order by a.id,a.colorder