SQL Server 2008 Management Studio에서 text 또는 varchar (MAX) 열의 전체 내용을 보려면 어떻게합니까?
이 라이브 SQL Server 2008 (빌드 10.0.1600) 데이터베이스에는 .txt 라는 열 Events
이 포함 된 테이블이 있습니다 . (예, 이것이 실제로 열 이어야한다는 것을 알고 있지만이 데이터베이스를 설정 한 사람은 그렇게하지 않았습니다.)text
Details
varchar(MAX)
이 열에는 SQL Server Management Studio를 통해 액세스하려는 매우 큰 예외 로그 및 관련 JSON 데이터가 포함되어 있지만 그리드에서 텍스트 편집기로 결과를 복사 할 때마다 43679 자로 잘립니다.
인터넷의 다양한 위치에서 XML 데이터에 대해 검색되는 최대 문자 Tools > Options > Query Results > SQL Server > Results To Grid
를 무제한으로 설정 한 다음 다음과 같은 쿼리를 수행 할 수 있다는 내용을 읽었습니다 .
select Convert(xml, Details) from Events
where EventID = 13920
(데이터는 열이 전혀 XML이 아닙니다. CONVERT
열을 XML로 변환하는 것은 다른 사람이 SSMS가 text
또는 varchar(MAX)
열 에서 데이터를 검색 할 때 갖는 한계를 극복하는 데 사용한 Google 검색에서 찾은 해결 방법 일뿐 입니다.)
그러나 위의 옵션을 설정하고 쿼리를 실행하고 결과의 링크를 클릭 한 후에도 여전히 다음 오류가 발생합니다.
XML을 표시 할 수 없습니다. 다음 오류가 발생했습니다. 예기치 않은 파일 끝이 발생했습니다. 5 행, 위치 220160.
한 가지 해결책은 XML 데이터에 대해 서버에서 검색되는 문자 수를 늘리는 것입니다. 이 설정을 변경하려면 도구 메뉴에서 옵션을 클릭합니다.
그렇다면 이 데이터에 액세스하는 방법에 대한 아이디어가 있습니까? varchar(MAX)
내 문제 를 해결 하기 위해 칼럼을 변환 할까요?
매우 제한된 상황에서 작동 할 수있는 한 가지 트릭은 아래와 같이 특별한 방식으로 열 이름을 지정하는 것입니다.
DECLARE @S varchar(max) = 'A'
SET @S = REPLICATE(@S,100000) + 'B'
SELECT @S as [XML_F52E2B61-18A1-11d1-B105-00805F49916B]
SSMS 2012 및 2014에서는 다음과 같은 결과가 표시됩니다.
그것을 클릭하면 XML 뷰어에 전체 결과가 열립니다. 오른쪽으로 스크롤하면 B의 마지막 문자가 유지되고
그러나 이것은 몇 가지 중요한 문제가 있습니다. 쿼리에 추가 열을 추가하면 효과가 중단되고 추가 행이 모두 첫 번째 행과 연결됩니다. 마지막으로 문자열 <
에 XML 뷰어 열기 와 같은 문자가 포함되어 있으면 구문 분석 오류와 함께 실패합니다.
SQL Server 가 이러한 문자로 변환 되거나 이러한 문자로 인해 실패 <
하는 문제를 방지하는보다 강력한 방법 <
은 다음과 같습니다 ( 신용 Adam Machanic 여기 ).
DECLARE @S varchar(max)
SELECT @S = ''
SELECT @S = @S + '
' + OBJECT_DEFINITION(OBJECT_ID) FROM SYS.PROCEDURES
SELECT @S AS [processing-instruction(x)] FOR XML PATH('')
나는 이것을 작동시킬 수 있었다 ...
SELECT CAST('<![CDATA[' + LargeTextColumn + ']]>' AS XML) FROM TableName;
One work-around is to right-click on the result set and select "Save Results As...". This exports it to a CSV file with the entire contents of the column. Not perfect but worked well enough for me.
Did you try this simple solution? Only 2 clicks away!
At the query window,
- set query options to "Results to Grid", run your query
- Right click on the results tab at the grid corner, save results as any files
You will get all the text you want to see in the file!!! I can see 130,556 characters for my result of a varchar(MAX) field
The simplest workaround I found is to backup the table and view the script. To do this
- Right click your database and choose
Tasks
>Generate Scripts...
- "Introduction" page click
Next
- "Choose Objects" page
- Choose the
Select specific database objects
and select your table. - Click
Next
- Choose the
- "Set Scripting Options" page
- Set the output type to
Save scripts to a specific location
- Select
Save to file
and fill in the related options - Click the
Advanced
button - Set
General
>Types of data to script
toData only
orSchema and Data
and click ok - Click
Next
- Set the output type to
- "Summary Page" click next
- Your sql script should be generated based on the options you set in 4.2. Open this file up and view your data.
The data type TEXT is old and should not be used anymore, it is a pain to select data out of a TEXT column.
ntext, text, and image (Transact-SQL)
ntext, text, and image data types will be removed in a future version of Microsoft SQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.
you need to use TEXTPTR (Transact-SQL) to retrieve the text data.
Also see this article on Handling The Text Data Type.
It sounds like the Xml may not be well formed. If that is the case, then you will not be able to cast it as Xml and given that, you are limited in how much text you can return in Management Studio. However, you could break up the text into smaller chunks like so:
With Tally As
(
Select ROW_NUMBER() OVER ( ORDER BY s1.object_id ) - 1 As Num
From sys.sysobjects As s1
Cross Join sys.sysobjects As s2
)
Select Substring(T1.textCol, T2.Num * 8000 + 1, 8000)
From Table As T1
Cross Join Tally As T2
Where T2.Num <= Ceiling(Len(T1.textCol) / 8000)
Order By T2.Num
You would then need to manually combine them again.
EDIT
It sounds like there are some characters in the text
data that the Xml parser does not like. You could try converting those values to entities and then try the Convert(xml, data)
trick. So something like:
Update Table
Set Data = Replace(Cast(Data As varchar(max)),'<','<')
(I needed to cast to varchar(max) because the replace function will not work on text
columns. There should not be any reason you couldn't convert those text
columns to varchar(max)
.)
You are out of luck, I think. THe problem is not a SQL level problem as all other answers seem to focus on, but simply one of the user interface. Management Studio is not meant to be a general purpose / generic data access interface. It is not there to be your interface, but your administrative area, and it has serious limitations handling binary data and large test data - because people using it within the specified usage profile will not run into this problem.
Presenting large text data is simply not the planned usage.
Your only choice would be a table valued function that takes the text input and cuts it rows for every line, so that Management Studio gets a list of rows, not a single row.
I prefer this simple XML hack which makes columns clickable in SSMS on a cell-by-cell basis. With this method, you can view your data quickly in SSMS’s tabular view and click on particular cells to see the full value when they are interesting. This is identical to the OP’s technique except that it avoids the XML errors.
SELECT
e.EventID
,CAST(REPLACE(REPLACE(e.Details, '&', '&'), '<', '<') AS XML) Details
FROM Events e
WHERE 1=1
AND e.EventID BETWEEN 13920 AND 13930
;
Starting from SSMS 18.2, you can now view up to 2 million characters in the grid results. Source
Allow more data to be displayed (Result to Text) and stored in cells (Result to Grid). SSMS now allows up to 2M characters for both.
I verified this with the code below.
DECLARE @S varchar(max) = 'A'
SET @S = REPLICATE(@S,2000000) + 'B'
SELECT @S as a
'development' 카테고리의 다른 글
HttpWebRequest를 사용하여 양식 데이터 게시 (0) | 2020.09.24 |
---|---|
VS2012 편집기 탭 색상을 끄는 방법은 무엇입니까? (0) | 2020.09.24 |
std :: type_info :: name 결과 관리 해제 (0) | 2020.09.24 |
ImportError : OS X에서 Python을 업그레이드 한 후 pkg_resources라는 모듈이없는 이유는 무엇입니까? (0) | 2020.09.24 |
$ _SERVER [ 'REMOTE_ADDR']을 신뢰하는 것이 안전합니까? (0) | 2020.09.24 |