在 SQL Server Management Studio 中查看 SQL CE 数据库的所有 ntext 列文本

发布于 2024-08-13 14:38:47 字数 844 浏览 4 评论 0原文

我经常想在 SQL Server Management Studio (SSMS) 中“快速检查”大型文本列的值。在网格结果模式下,SSMS 允许您查看的最大字符数为 65535。(在文本结果模式下甚至更少。)有时我需要查看超出该范围的内容。使用 SQL Server 2005 数据库时,我经常使用将其转换为 XML 的技巧,因为 SSMS 允许您以这种方式查看大量文本:

SELECT CONVERT(xml, MyCol) FROM MyTable WHERE ...

但现在我使用 SQL CE,并且没有 Xml 数据类型。选项下还有一个“Maximum Characters Retreived XML”值;我认为这在连接到其他数据源时很有用。

我知道我可以通过运行一个小控制台应用程序或其他东西来获取完整值,但是 SSMS 中有没有办法查看整个 ntext 列值?

[编辑] 好吧,第一次并没有引起太多关注(18 次浏览?!)。这不是一个大问题,但也许我只是对此着迷。 必须有一些好的方法来解决这个问题,不是吗?因此,适度的赏金是活跃的。我愿意接受的答案(按从最好到最差的顺序排列):

  1. 一个与 SQL CE 中的 XML 技巧一样简单的解决方案。也就是说,一个函数(转换、转换等)可以完成这项工作。
  2. 一种不太侵入性的方法来破解 SSMS,使其在结果中显示更多文本。
  3. 一个等效的 SQL 查询(也许创造性地使用 SUBSTRING 并生成多个临时列??)来查看结果。

该解决方案应适用于 SSMS 的 SQL CE 中任意长度的 nvarchar 和 ntext 列。有什么想法吗?

I often want to do a "quick check" of the value of a large text column in SQL Server Management Studio (SSMS). The maximum number of characters that SSMS will let you view, in grid results mode, is 65535. (It is even less in text results mode.) Sometimes I need to see something beyond that range. Using SQL Server 2005 databases, I often used the trick of converting it to XML, because SSMS lets you view much larger amounts of text that way:

SELECT CONVERT(xml, MyCol) FROM MyTable WHERE ...

But now I am using SQL CE, and there is no Xml data type. There is still a "Maximum Characters Retreived XML" value under Options; I suppose this is useful when connecting to other data sources.

I know I can just get the full value by running a little console app or something, but is there a way within SSMS to see the entire ntext column value?

[Edit] OK, this didn't get much attention the first time around (18 views?!). It's not a huge concern, but maybe I'm just obsessed with it. There has to be some good way around this, doesn't there? So a modest bounty is active. What I am willing to accept as answers, in order from best-to-worst:

  1. A solution that works just as easy as the XML trick in SQL CE. That is, a single function (convert, cast, etc.) that does the job.
  2. A not-too-invasive way to hack SSMS to get it to display more text in the results.
  3. An equivalent SQL query (perhaps something that creatively uses SUBSTRING and generates multiple ad-hoc columns??) to see the results.

The solution should work with nvarchar and ntext columns of any length in SQL CE from SSMS. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忘东忘西忘不掉你 2024-08-20 14:38:47

如果您使用支持 TOP 和 OUTER APPLY 的 CE 3.5,请尝试此操作声明:

SELECT texts.id, SUBSTRING(texts.text_column, number*100+1, 100)
FROM 
    (SELECT texts.id, texts.text_column, (99+LEN(texts.text_column))/100 AS l 
     FROM texts) AS texts
OUTER APPLY 
    (SELECT TOP(l) number 
     FROM master.dbo.spt_values val 
     WHERE name IS NULL 
     ORDER BY number) n

100(和99)是我在数据中用于测试的文本长度。

If you work with CE 3.5 supporting TOP and OUTER APPLY, try this statement:

SELECT texts.id, SUBSTRING(texts.text_column, number*100+1, 100)
FROM 
    (SELECT texts.id, texts.text_column, (99+LEN(texts.text_column))/100 AS l 
     FROM texts) AS texts
OUTER APPLY 
    (SELECT TOP(l) number 
     FROM master.dbo.spt_values val 
     WHERE name IS NULL 
     ORDER BY number) n

100 (and 99) is the text length I used for testing in my data.

最后的乘客 2024-08-20 14:38:47

这可能不太理想,但是您可以在以文本模式查看它时将其分解吗?

例如:

SELECT
     SUBSTRING(my_text, 1, 8000),
     SUBSTRING(my_text, 8001, 8000)
FROM
     dbo.My_Table

它在 SQL 2008 中按原样工作。对于 2005,您可能需要对 VARCHAR(MAX) 进行 CAST,我不确定这是否会按预期工作。

我刚刚在 2008 年提出了以下查询(我手头没有 CE 版本),它对于大多数未知长度的文本(我认为限制为 800,000 个字符,您可能不想只显示它)效果很好反正)。这些块作为单独的行出现,因此您可能会在文本中间有回车符。我不知道这是否是一个问题。

;WITH my_cte AS
(
    SELECT
        SUBSTRING(my_text, 1, 8000) AS sub,
        SUBSTRING(my_text, 8001, LEN(CAST(my_text AS VARCHAR(MAX)))) AS remainder
    FROM
        dbo.Test_Text
    UNION ALL
    SELECT
        SUBSTRING(remainder, 1, 8000),
        SUBSTRING(remainder, 8001, LEN(remainder))
    FROM
        my_cte
    WHERE
        LEN(remainder) > 0
)
SELECT
    *
FROM
    my_cte

This may not be ideal, but can you break it up while viewing it in text mode?

For example:

SELECT
     SUBSTRING(my_text, 1, 8000),
     SUBSTRING(my_text, 8001, 8000)
FROM
     dbo.My_Table

It works as-is in SQL 2008. For 2005 you might need to do a CAST to VARCHAR(MAX) and I'm not sure if that would work as expected or not.

I just came up with the following query in 2008 (I don't have a CE version handy) and it worked well for a mostly unknown length of text (limit of 800,000 characters I think, which you probably don't want to just display anyway). The chunks come out as separate rows, so you may have carriage returns in the middle of your text because of that. I don't know if that's an issue or not.

;WITH my_cte AS
(
    SELECT
        SUBSTRING(my_text, 1, 8000) AS sub,
        SUBSTRING(my_text, 8001, LEN(CAST(my_text AS VARCHAR(MAX)))) AS remainder
    FROM
        dbo.Test_Text
    UNION ALL
    SELECT
        SUBSTRING(remainder, 1, 8000),
        SUBSTRING(remainder, 8001, LEN(remainder))
    FROM
        my_cte
    WHERE
        LEN(remainder) > 0
)
SELECT
    *
FROM
    my_cte
冰魂雪魄 2024-08-20 14:38:47

根据此 http://msdn.microsoft.com/en-us/library/ ms171931.aspx 您在 SQL CE 中使用 XML 类型不走运。它根本不存在。您仍然会得到一个 2gb BLOB ntext 字段,但这没有任何帮助。

select ... as xml 在 ce 查询中工作,但看起来网格仍然将其截断为 ntext。要进行测试,请创建一个名为 Test 的表,其中 char 为 nvarchar(4000),文本为 ntext 字段。使用以下语句填充数据并返回:

select char, text from test as xml

insert into test (char, text) values (replicate('A',4000),replicate( 'b',4000) +replicate('B',4000))

我在网格模式下在大致相同的位置截断了两个字段,这表明它截断的位置远小于 65535。删除 as xml 没有任何效果,因此它实际上不会转入 XML 数据。

您的答案:

  1. 不允许强制转换,但转换是有效的。问题:引擎中没有 xml 类型。可能的长解决方法:将数据导入 SQL Express 数据库临时数据库,否则将获得正确的类型。这不是一个小壮举,除非你能处理好开销。
  2. SSMS 正在变得可扩展,但我想说这是不可能的。它是一个 .NET 应用程序,可以在 Reflector 中查看,但这并不能说明什么。
  3. 遗憾的是,虽然这是最糟糕的选择,但从 SSMS 的角度来看,它似乎确实是最简单的选择。您仍然需要自动调整每列的大小,但希望您不会将其分成超过 2-3 列。

然而,归根结底,我不禁认为所有这些仍然是浪费时间。也许您可以找到一个更好的 SQL CE 专用工具,您可以用它来编辑架构并以正确的方式查看每一列。事情发展到这一步有点令人难过,但我没有看到更简单的选择。

Per this http://msdn.microsoft.com/en-us/library/ms171931.aspx you're out of luck using the XML type in SQL CE. It simply does not exist. You still get a 2gb BLOB ntext field but that's no help.

select ... as xml works in a ce query but it looks like the Grid still truncates it as ntext. To test create a table named Test with char as nvarchar(4000) and text as ntext fields. Use the following statements to fill data and return it:

select char, text from test as xml

insert into test (char, text) values (replicate('A',4000), replicate('b',4000) + replicate('B',4000))

I get both fields truncating at roughly the same spot in grid mode which would suggest it truncates at much less than 65535. Removing the as xml has no effect so it isn't actually going to XML data anyway.

Your answers:

  1. You're not allowed cast but convert is valid. Problem: No xml type in the engine. Possible long workaround: farm the data into a SQL Express database temp or otherwise will get the proper type. Not a small feat unless you can handle the overhead.
  2. SSMS is getting extensible but I would say this is a non-starter. It is a .NET app and can be viewed in Reflector but that doesn't suggest much.
  3. While the worst option it does seem like the easiest from an SSMS standpoint, sadly. You're still having to auto-resize each column but hopefully you wouldn't be breaking it up into more than 2-3.

At the end of the day, however, I can't help but think that all of these would still be a waste of time. Perhaps you could find a better SQL CE only tool that you can edit the schema and view every column in a proper manner. It's kinda sad that it would even come to this but I don't see an easier option.

深陷 2024-08-20 14:38:47

我确实喜欢这样(在调试模式下启动代码),执行设置指令后,您可以从调试窗口复制大文本,在其中看到 @x 值,单击放大镜/文本可视化工具:

declare @x varchar(max);

set @x = (select ioub_application_payload from integrator..tbl_interface_outbound where ioub_iz_id = 74)

PRINT (@x)

I do like this (start the code under in debug mode) and after executing the set instruction you can just copy the large text from the debug window where you see the @x value, click on the Magnifier/Text visualizer :

declare @x varchar(max);

set @x = (select ioub_application_payload from integrator..tbl_interface_outbound where ioub_iz_id = 74)

PRINT (@x)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文