When developing, it is not necessary to use SQL to directly interact with the database, when the table names and field names in the database are used more. If you copy one every time you use it, the egg hurts. So consider making it a const constant. But there are quite a few tables and fields in the database, one knocking, not only tired, but also possibly knocking the wrong. The best way to ensure that you are right is to use tools or scripts, of course.
A SQL script implementation is provided here.
Principle: Get the table---of the database > traverse the fields in each table---> Generate data
SQL code
DECLARE @tableName VARCHAR (MAX)
DECLARE @tableCount int
DECLARE @tableIndex int
DECLARE @tempTable TABLE
(
DATA VARCHAR (MAX)
)
SELECT @tableCount =count (*) from SysObjects WHERE xtype= ' U '
--xtype= ' U ': represents all user tables;
--xtype= ' S ': denotes all system tables;
SET @tableIndex =1
While @tableIndex <[email protected]
BEGIN
SELECT @tableName =name
From
(
SELECT row_number () over (ORDER by NAME) as Tempno,name from SysObjects
WHERE xtype= ' U '
) TEMP
WHERE [email protected]
INSERT into @tempTable VALUES (")
INSERT into @tempTable VALUES (' #region ' [email protected])
INSERT into @tempTable VALUES (' Public sealed class ' [email protected]+ ' {')
INSERT into @tempTable the Select ' Public const string ' +name+ ' = ' +name+ ' "; ' From syscolumns WHERE ID in
(SELECT ID from sysobjects WHERE [email protected])
INSERT into @tempTable VALUES ('} ')
INSERT into @tempTable VALUES (' #endregion ')
INSERT into @tempTable VALUES (")
SET @tableIndex +=1
END
SELECT * from @tempTable
Results of the Build
result graphs in SQL
Result graphs in C #
Specific adjustments can be made as needed
[Go] Extract database tables and fields as classes in C # based on SQL scripts