简体   繁体   English

SQL Server 2008 RegEx CLR使用

[英]SQL Server 2008 RegEx CLR Use

OK, I realize that SS 2008 doesn't have native regex functions. 好的,我意识到SS 2008没有本地正则表达式功能。 I also see that it's possible to add them using CLR. 我还看到可以使用CLR添加它们。 I found the regex CLR at http://msdn.microsoft.com/en-us/magazine/cc163473.aspx , but I don't know what to do with them. 我在http://msdn.microsoft.com/zh-cn/magazine/cc163473.aspx上找到了正则表达式CLR,但我不知道如何处理它们。

So I have 2 questions. 所以我有两个问题。 The regex is only used when importing records (up to 1,000,000 at a time, and up to 50,000,000 a year) against 2 fields. 仅当针对两个字段导入记录(一次最多1,000,000,每年最多50,000,000)时,才使用正则表达式。

1st question. 第一个问题。 I can do it manually 1 record at a time in my code (ASP.NET), and I know it would be a performance hit, but no idea how big of one. 我可以在我的代码(ASP.NET)中一次手动记录1条记录,我知道这会降低性能,但是不知道有多大。 Any input on this? 有什么意见吗?

2nd question. 第二个问题。 Can someone point me to a simple step by step instruction on how to install the CLR files I downloaded? 有人可以向我指出有关如何安装我下载的CLR文件的简单分步说明吗? I tried doing a search, but that either didn't show the info I needed, or was too buried in other info for me to find it. 我尝试进行搜索,但是该搜索未显示我所需的信息,或者被其他信息所掩盖,以至于我找不到它。

Thanks 谢谢

PS I'm running SS 2008 (not R2) and VS.NET 2008. PS我正在运行SS 2008(不是R2)和VS.NET 2008。

有关完整的教程,请参见此处文章

If you only need REGEX for a dataload then you could do it one record at a time in ASP.NET. 如果只需要REGEX进行数据加载,则可以在ASP.NET中一次完成一条记录。 Even with SQL CLR integration you would be doing it one record at a time as SQL would pass the value one records at a time. 即使使用SQL CLR集成,您一次也要记录一次,因为SQL一次要传递一个记录的值。 If you want to use REGEX as a condition in the where clause then SQL CLR integration would be the only option. 如果要在where子句中使用REGEX作为条件,则SQL CLR集成将是唯一的选择。

What I am doing is parsing one line at a time. 我正在做的是一次解析一行。 One line will result in 1 - 5 SQL inserts. 一行将导致1-5次SQL插入。 Then I do those SQL inserts asynch. 然后,我执行那些SQL插入异步。 If the next parse completes before the insert I wait. 如果下一个解析在插入之前完成,我将等待。 In my case it is about a dead heat so I get parallel processing. 就我而言,这几乎是一团糟,所以我进行了并行处理。 If SQL calls regex you are limited to serial processing. 如果SQL调用正则表达式,则只能进行串行处理。

I parse and load data a lot. 我经常分析和加载数据。 If you are concerned about speed look more at the SQL side than parse. 如果您担心速度,则更多地关注SQL方面而不是解析。 I go so far as to disable SQL indexes parse and load 10 million records and then rebuild indexes. 我甚至禁用了SQL索引解析,并加载了1000万条记录,然后重建索引。 Regex a line at time is typically faster than SQL insert unless the SQL table has no indexes. 除非SQL表没有索引,否则正则表达式的时间通常比SQL插入快。

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

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