I'll show you how to do it and then briefly discuss the pros and cons of archiving SQL tables this way.
There's two steps to this method. First export the data:
- Create a batch (.bat) file in Windows.
- Enter the following code inside the batch file:
bcp "select Col1, Col2, Col3 from Database.user.TableName" queryout c:\bulkcopy\tablename.txt -n -Sserver -Usa -P
Obviously the column names, table and location need to be replaced. After the capital S you can replace the word server with the server that has SQL installed. After the capital U you can replace sa with your user name. After the capital P enter your password. - Double click on the batch file and watch it run. Could take a bit if it's a large file.
- Right click on the table in your object explorer.
- Click Script Table as | CREATE To | New Query Editor Window
- Save the file.
Pros:
- Only a little extra effort for one vs multiple tables
- Can run unattended
- Importing data is really easy
- Relatively large files depending on how many columns/rows each table has
- No was to review the data in a meaningful way outside of rebuilding the table and inserting the table
- Might not have access to this unless you are an admin
No comments:
Post a Comment