regex – 用于验证SQL Server表名的正则表达式

我正在使用C#代码创建动态sql Server表,但我需要验证表名.

什么是验证sql Server表名的正则表达式?

解决方法

link中描述的正则表达式应该是:
var regex = new Regex(@"^[\p{L}_][\p{L}\p{N}@$#_]{0,127}$");

请注意,通常你必须在[…]中嵌入表的名称,因为规则3(所以SELECT * FROM [SET]是一个有效的查询,因为,虽然SET是保留关键字,你可以用[…]“逃避”它

请注意,在链接页面中,规则不完整:

https://msdn.microsoft.com/en-us/library/ms175874.aspx开始

>标识符不能是Transact-sql保留字. sql Server保留保留字的大写和小写版本.在Transact-sql语句中使用标识符时,不符合这些规则的标识符必须用双引号或括号分隔.保留的单词取决于数据库兼容级别.可以使用ALTER DATABASE语句设置此级别.

他们忘记了:https://msdn.microsoft.com/en-us/library/ms174979.aspx

Is the name of the new table. Table names must follow the rules for identifiers. table_name can be a maximum of 128 characters,except for local temporary table names (names prefixed with a single number sign (#)) that cannot exceed 116 characters.

我编写的规则是针对“完整”表,而不是针对临时表,并且不包括模式名称.

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...