简体   繁体   English

将验证规则中带有正则表达式的 MS-Access 表迁移到 SQL-Server

[英]Migrate MS-Access tables with Regular Expression in Validation Rule to SQL-Server

I'm migrating a MS-Access.accdb-database to SQL Server 2017. In my MS Access database, there is a lot of table columns with validation rule like "NOT LIKE [.a-z0-9.] ".我正在将 MS-Access.accdb-database 迁移到 SQL Server 2017。在我的 MS Access 数据库中,有很多表列的验证规则类似于“NOT LIKE [.a-z0-9.] ”。 I cannot find any way to add a constraint in SQL Server that do the same thing.我找不到任何方法在 SQL 服务器中添加做同样事情的约束。 Is there a way to do this, or is it simply impossible to migrate MS Access to SQL-Server without losing functionality?有没有办法做到这一点,或者根本不可能在不丢失功能的情况下将 MS Access 迁移到 SQL-Server?

ALTER TABLE [Zones]
    ADD CONSTRAINT [CHK_Zon]
        CHECK ([Zon] NOT LIKE '*[!a-z0-9.]*')

I think you want:我想你想要:

NOT LIKE '%[^a-z0-9.]%'

This will mean that only the letters a to z , the numerals 0 to 9 and the character .这将意味着只有字母az 、数字09和字符. will be allowed.将被允许。 Note that all or some upper case letters may be allowed, depending on your collation, and all lowercase letters, with az .请注意,可能允许使用全部或部分大写字母,具体取决于您的排序规则,以及使用az的所有小写字母。

% are multi-character wildcards. %是多字符通配符。

The ^ (carat) symbol means "Any single character not within the specified range" . ^ (克拉)符号表示“任何不在指定范围内的单个字符” So, for example, 'Test' NOT LIKE '%[^Az]%' would return TRUE, as it only contains the characters in the range Az (it doesn't contain any outside of it.因此,例如, 'Test' NOT LIKE '%[^Az]%'将返回 TRUE,因为它只包含Az范围内的字符(它不包含它之外的任何字符。

SQL Server does not support Regex (not natively anyway, it can by use of CLR functions), it only has simply pattern matching; SQL 服务器不支持正则表达式(反正原生不支持,通过CLR函数可以),只有简单的模式匹配; which you can read about here .你可以在这里阅读。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM