Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How schema tables data export to xml?

Author  Topic 

getur.srikanth@gmail.com
Yak Posting Veteran

77 Posts

Posted - 2011-05-19 : 15:57:16
I have a database having 12 tables. I want to export 1000 records from each of the table to xml files? How can we do that?

Thanks in advance.

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-05-19 : 22:38:19
You can export using bcp. The syntax is something like this:

bcp "select top 1000 * from DBName.dbo.TableName for xml auto" queryout filename.txt -T -c
There are various other options you can specify - http://msdn.microsoft.com/en-us/library/ms162802.aspx

You can specify additional options for the xml auto clause. For example:

1. If you want a root element, specify the option root('YourRoot')
2. If you would like the columns to be elements instead of attributes, specify elements option.

bcp "select top 1000 * from DBName.dbo.TableName for xml auto, root('YourRoot'), elements" queryout filename.txt -T -c


You will need to run bcp either from a command line window or using xp_cmdshell.

Go to Top of Page

jooorj
Posting Yak Master

126 Posts

Posted - 2011-05-20 : 11:37:19
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'queryout'.
Go to Top of Page
   

- Advertisement -