Article

Your First SQL Server 2000 Database

Page: 1 2 3 4 5 6 7 8

Retrieve data as XML

SQL Server 2000 supports the FOR XML clause, which we can use to easily return records as XML data. Use the following code in Query Analyzer to return all rows from our widgets table as XML elements:

USE MyDatabase1        
GO        
       
SELECT 1 AS Tag,        
NULL AS Parent,        
widgetName AS [Widget!1!Name],        
widgetPrice AS [Widget!1!Price],        
widgetAvailable AS [Widget!1!Available]        
FROM widgets        
FOR XML EXPLICIT        
GO

The XML will be returned as one record and will something look like this:

<Widget Name="Red Widget" Price="9.9500" Available="1"/>        
<Widget Name="Blue Widget" Price="14.5000" Available="1"/>        
<Widget Name="Green Widget" Price="24.9500" Available="1"/>        
...

For more detail on retrieving XML data from SQL Server, see my article "Retrieving Data as XML from SQL Server".

Conclusion

In this article we've created an SQL Server 2000 database from scratch. We used Enterprise Manager and Query Analyzer to accomplish the same goals, and we finished off by looking at some TSQL commands we can use to manipulate our database. If you've never worked with SQL Server 2000 before then hopefully this article has given you the information you need to get started!

If you liked this article, share the love:
Print-Friendly Version Suggest an Article

Sponsored Links

Rate This Article

  • 1
    Poor
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
    Great

Comment on This Article

Have something to say?

Post A Comment

You need to be a member of the SitePoint Forums to comment on this post. Sign Up

Already a member? Post using your SitePoint Forums account: