Showing posts with label sql server. Show all posts
Showing posts with label sql server. Show all posts

Tuesday, May 10, 2011

Any fix to SQL Server Management Studio timing out when Adding a New Column to a Table

A while back I posted the inquiry http://nullpointer.ph/questions/3204/any-fix-to-sql-server-management-studio-timing-out-when-adding-a-new-column-to-a-table

Thanks to Alistair sharing his knowledge. After some research got the following fix

tools-options-designers-tables-and-database-designers

that is, navigating Tools > Options then looking at Designers > Table and Database Designers node you will have Table Options. Override the default value of Transaction time-out after: [____] seconds with your desired length of time.

Saturday, May 7, 2011

Extracting Data from an XML file in MS SQL Server

 

Assuming you have an XML file structured as follows

<questionnaire>

<question>

<id>1</id>

<text>Which of the following is TRUE?</text>

<option1>6 is a perfect number.</option1>

<option2>All prime numbers are odd.</option2>

<option3>None of the Above</option3>

<answer>B</answer>

<explanation>B is FALSE because 2 is prime and even.

Perfect Numbers are such that the sum of their prime factors and 1 equals the number. Since the prime factors of 6 are 2 and 3 and 2+3+1 = 6, then 6 must be perfect.</explanation>

</question>

…

</questionnaire>

 

and there are a thousand more <question> … </question> set in it but you are interested only in retrieving the id and answer. Using SQL Server 2008, what SQL statements should you use?

Here it is:

-------------------------------------------------

DECLARE @FilePath AS VARCHAR(50)
DECLARE @Query AS NVARCHAR(MAX)
DECLARE @QuestionData XML

-- set the path to xml file

SET @FilePath = 'C:\Users\test\questions.xml'

SET @Query = N'SELECT @data = CAST(BulkColumn AS XML) FROM OPENROWSET(BULK N''' + @FilePath + ''', SINGLE_BLOB) AS XmlData'

EXEC sp_executesql @Query, N'@data AS XML OUTPUT', @QuestionData OUTPUT

DECLARE @hdoc int

EXEC sp_xml_preparedocument @hdoc OUTPUT, @QuestionData

SELECT
    *
FROM
    OPENXML (@hdoc, '/questionnaire/question', 10)
    WITH (
        id INT,
        answer CHAR(1)
    )

EXEC sp_xml_removedocument @hdoc

-------------------------------------------------

Simple eh?

Monday, September 6, 2010

How to Install SQL Server Management Studio 2008 Express Edition

Frustrating as it is, SQL Server Management Studio 2008 Express is NOT part of the "normal" SQL Server 2008 express installation.

How then it could get installed?
Download SQLManagementStudio_x86_ENU.exe here http://www.microsoft.com/downloads/details.aspx?FamilyID=08e52ac2-1d62-45f6-9a4a-4b76a8564a2b

Run it and wait until the below is displayed


Select the "New SQL Server stand-alone installation..." link option. Follow the usual installtion but upon reaching the below dialog box, select the "Perform a new isntallation of SQL Server 2008" option.


When you reach the "Feature Selection" dialog, check the "Management Tools - Basic" option.


Continue the installation process and once complete SQL Server Management Studio will be foound in your Program Files list.



Simple eh?