我希望在C#程序中运行时获得所有t-sql保留关键字的列表。
bool iskeyword = IsSqlReservedKeyword("string");
或
list<string> ReservedKeywordList = new list<string>();
ReservedKeywordList = GetSQLReservedKeywords();
与C#类似,有一种方法IsValidIdentifier("string")
。 SQL类型有类似的方法吗?
答案 0 :(得分:3)
所有保留(以及将来可能保留的)关键字都是listed on MSDN。您需要设置一个自己返回此单词列表的属性。有点不确定,但你只需要做一次。
我可能会写一些Perl或Python脚本来解析该页面并为我创建属性。可能需要更长的时间,但它比手动操作更有趣,而且可以在此过程中学到一些东西。
答案 1 :(得分:0)
您需要创建一个列表并通过将所有字符串放在该列表中来填充此列表。您可以从Michael给出的路径中选择字符串。类似的东西:
private List<String> CreateSQLReservedKeywordList()
{
List<String> list = new List<String>();
list.Add("Exists");
list.Add("RaiseError");
...
}
出于高级目的,您可以创建Excel或CSV并从这些文件中填充列表。
答案 2 :(得分:0)
这是 C# 中的列表(您可以在此处找到列表:https://docs.microsoft.com/en-us/sql/t-sql/language-elements/reserved-keywords-transact-sql):
List<string> reservedKeywords = new List<string>()
{
{ "ADD" },
{ "EXTERNAL" },
{ "PROCEDURE" },
{ "ALL" },
{ "FETCH" },
{ "PUBLIC" },
{ "ALTER" },
{ "FILE" },
{ "RAISERROR" },
{ "AND" },
{ "FILLFACTOR" },
{ "READ" },
{ "ANY" },
{ "FOR" },
{ "READTEXT" },
{ "AS" },
{ "FOREIGN" },
{ "RECONFIGURE" },
{ "ASC" },
{ "FREETEXT" },
{ "REFERENCES" },
{ "AUTHORIZATION" },
{ "FREETEXTTABLE" },
{ "REPLICATION" },
{ "BACKUP" },
{ "FROM" },
{ "RESTORE" },
{ "BEGIN" },
{ "FULL" },
{ "RESTRICT" },
{ "BETWEEN" },
{ "FUNCTION" },
{ "RETURN" },
{ "BREAK" },
{ "GOTO" },
{ "REVERT" },
{ "BROWSE" },
{ "GRANT" },
{ "REVOKE" },
{ "BULK" },
{ "GROUP" },
{ "RIGHT" },
{ "BY" },
{ "HAVING" },
{ "ROLLBACK" },
{ "CASCADE" },
{ "HOLDLOCK" },
{ "ROWCOUNT" },
{ "CASE" },
{ "IDENTITY" },
{ "ROWGUIDCOL" },
{ "CHECK" },
{ "IDENTITY_INSERT" },
{ "RULE" },
{ "CHECKPOINT" },
{ "IDENTITYCOL" },
{ "SAVE" },
{ "CLOSE" },
{ "IF" },
{ "SCHEMA" },
{ "CLUSTERED" },
{ "IN" },
{ "SECURITYAUDIT" },
{ "COALESCE" },
{ "INDEX" },
{ "SELECT" },
{ "COLLATE" },
{ "INNER" },
{ "SEMANTICKEYPHRASETABLE" },
{ "COLUMN" },
{ "INSERT" },
{ "SEMANTICSIMILARITYDETAILSTABLE" },
{ "COMMIT" },
{ "INTERSECT" },
{ "SEMANTICSIMILARITYTABLE" },
{ "COMPUTE" },
{ "INTO" },
{ "SESSION_USER" },
{ "CONSTRAINT" },
{ "IS" },
{ "SET" },
{ "CONTAINS" },
{ "JOIN" },
{ "SETUSER" },
{ "CONTAINSTABLE" },
{ "KEY" },
{ "SHUTDOWN" },
{ "CONTINUE" },
{ "KILL" },
{ "SOME" },
{ "CONVERT" },
{ "LEFT" },
{ "STATISTICS" },
{ "CREATE" },
{ "LIKE" },
{ "SYSTEM_USER" },
{ "CROSS" },
{ "LINENO" },
{ "TABLE" },
{ "CURRENT" },
{ "LOAD" },
{ "TABLESAMPLE" },
{ "CURRENT_DATE" },
{ "MERGE" },
{ "TEXTSIZE" },
{ "CURRENT_TIME" },
{ "NATIONAL" },
{ "THEN" },
{ "CURRENT_TIMESTAMP" },
{ "NOCHECK" },
{ "TO" },
{ "CURRENT_USER" },
{ "NONCLUSTERED" },
{ "TOP" },
{ "CURSOR" },
{ "NOT" },
{ "TRAN" },
{ "DATABASE" },
{ "NULL" },
{ "TRANSACTION" },
{ "DBCC" },
{ "NULLIF" },
{ "TRIGGER" },
{ "DEALLOCATE" },
{ "OF" },
{ "TRUNCATE" },
{ "DECLARE" },
{ "OFF" },
{ "TRY_CONVERT" },
{ "DEFAULT" },
{ "OFFSETS" },
{ "TSEQUAL" },
{ "DELETE" },
{ "ON" },
{ "UNION" },
{ "DENY" },
{ "OPEN" },
{ "UNIQUE" },
{ "DESC" },
{ "OPENDATASOURCE" },
{ "UNPIVOT" },
{ "DISK" },
{ "OPENQUERY" },
{ "UPDATE" },
{ "DISTINCT" },
{ "OPENROWSET" },
{ "UPDATETEXT" },
{ "DISTRIBUTED" },
{ "OPENXML" },
{ "USE" },
{ "DOUBLE" },
{ "OPTION" },
{ "USER" },
{ "DROP" },
{ "OR" },
{ "VALUES" },
{ "DUMP" },
{ "ORDER" },
{ "VARYING" },
{ "ELSE" },
{ "OUTER" },
{ "VIEW" },
{ "END" },
{ "OVER" },
{ "WAITFOR" },
{ "ERRLVL" },
{ "PERCENT" },
{ "WHEN" },
{ "ESCAPE" },
{ "PIVOT" },
{ "WHERE" },
{ "EXCEPT" },
{ "PLAN" },
{ "WHILE" },
{ "EXEC" },
{ "PRECISION" },
{ "WITH" },
{ "EXECUTE" },
{ "PRIMARY" },
{ "WITHIN GROUP" },
{ "EXISTS" },
{ "PRINT" },
{ "WRITETEXT" },
{ "EXIT" },
{ "PROC" }
};