DECLARE @tableName VARCHAR(MAX)
DECLARE @tableCount int
DECLARE @tableIndex int
DECLARE @tempTable TABLE
(
Header VARCHAR(100),
DType VARCHAR(100),
DATA VARCHAR(MAX)
)
SELECT @tableCount=COUNT(*) FROM SysObjects WHERE XType='U'
--XType='U':表示所有用户表;
--XType='S':表示所有系统表;
SET @tableIndex=1
WHILE @tableIndex<=@tableCount
BEGIN
SELECT @tableName=NAME
FROM
(
SELECT ROW_NUMBER() OVER(ORDER BY NAME) AS TempNO,NAME FROM SysObjects
WHERE XType='U'
) TEMP
WHERE TempNO=@tableIndex
INSERT INTO @tempTable VALUES('','','')
INSERT INTO @tempTable VALUES('#region ' ,@tableName,'')
INSERT INTO @tempTable VALUES('public partial class ' ,@tableName,'')
INSERT INTO @tempTable VALUES( '{','','')
INSERT INTO @tempTable select 'public ',data_type , column_name +'{get;set;}'
from information_schema.columns
where table_name=@tableName and data_type<>'xml'
INSERT INTO @tempTable VALUES( '}','','')
INSERT INTO @tempTable VALUES('#endregion','','')
INSERT INTO @tempTable VALUES('','','')
SET @tableIndex+=1
update @tempTable set DType = 'int'
where DType = 'int'
update @tempTable set DType = 'int64'
where DType = 'bigint'
update @tempTable set DType = 'byte[]'
where DType = 'binary'
update @tempTable set DType = 'byte[]'
where DType = 'image'
update @tempTable set DType = 'string'
where DType = 'char'
update @tempTable set DType = 'string'
where DType = 'nchar'
update @tempTable set DType = 'string'
where DType ='nvarchar'
update @tempTable set DType = 'string'
where DType = 'text'
update @tempTable set DType = 'string'
where DType = 'ntext'
update @tempTable set DType = 'bool'
where DType ='bit'
update @tempTable set DType = 'double'
where DType ='decimal'
update @tempTable set DType = 'double'
where DType ='numeric'
update @tempTable set DType = 'Single'
where DType ='real'
update @tempTable set DType = 'DateTime'
where DType ='date'
update @tempTable set DType = 'DateTime'
where DType ='datetime'
update @tempTable set DType = 'DateTime'
where DType ='smalldatetime'
update @tempTable set DType = 'DateTime'
where DType ='timestamp'
update @tempTable set DType = 'int16'
where DType ='smallint'
update @tempTable set DType = 'double'
where DType ='smallmoney'
update @tempTable set DType = 'double'
where DType ='money'
END
SELECT * FROM @tempTable