I need a full dump of my SQL server database in one large XML file. I need to get all the tables, except on some tables I need to exclude specific columns, (columns with raw data).
How can I do this?
I am using SQL server 2008 R2.
Never tried it, but I believe you can use the bulk export option of bcp:
From SQL Server Books on-line:
"E. Bulk exporting XML data
The following example uses bcp to bulk export XML data from the table that is created in the preceding example by using the same XML format file. In the following bcp command, and represent placeholders that must be replaced with appropriate values:
bcp bulktest..xTable out a-wn.out -N -T -S<server_name>\<instance_name>
"
Related
As an example how want to know how i can migarte my sql data that i previously made a sql dump for my db but now i want to dump the generated sql data into my local postgres
I have an SQL query that generates a result regarding the daily data from the database. I want a csv formatted file to be generated everyday with this query and saved in a folder. Is there any way I can do this?
NOTE: I am using SQL Server Management Studio 2008 with regards to the DB.
This is a question about bulk export which well documented in MSDN - Importing and Exporting Bulk Data
Is there a command line interface where I can run a script that says, for example:
Connect to server a
Run query 1
Connect to server b
Run query 2
Run query 3
I tried searching online but couldnt find anything built into SQL Server Management Studio.
Thanks!
The sqlcmd Utility
http://msdn.microsoft.com/en-us/library/ms162773.aspx
It usually ships with the SQL Server installer and is located in the following directory by default:
C:\Program Files\Microsoft SQL Server\100\Tools\Binn\SQLCMD.EXE
If you want to export in/out there is a command-line utility called BCP that will let you execute these types of processes.
bcp Utility
The bcp utility bulk copies data between an instance of Microsoft SQL
Server and a data file in a user-specified format. The bcp utility can
be used to import large numbers of new rows into SQL Server tables or
to export data out of tables into data files. Except when used with
the queryout option, the utility requires no knowledge of
Transact-SQL. To import data into a table, you must either use a
format file created for that table or understand the structure of the
table and the types of data that are valid for its columns.
I have a little problem. My friend has a database with over 10 tables and each table has over 90-100 records.
I can't find a workaround to export the records (to put in a SQL file something like this: INSERT INTO .... VALUES ... for each existing records) from his tables to import in my database.
How to do that ?
I tried: right click on a table -> Script Table as -> INSERT TO -> File ...
but it only generate the INSERT statement.
There are a solution ? or this feature is only for commercial version ?
UPDATE
You can use BCP command with command prompt like this
For export: bcp ADatabase.dbo.OneTable out d:\test\OneTable.bcp -c -Usa -Ppassword
For import: bcp ADatabase.dbo.OneTable in d:\test\OneTable.bcp -c -Usa -Ppassword
these commands will create a BCP file which contains records for specified table. You can import using existing BCP file into another database
If you use remote database then:
bcp ADatabaseRemote.dbo.OneTableRemote out d:\test\OneTableRemote.bcp -Slocalhost/SQLExpress -Usa -Ppassword
Instead of localhost/SQLExpress, you can use localhost or other server name...
Probably the simplest way to do this would be to run a SELECT statement that outputs to a file. Then you can import that data into your database.
For simple moves, I have also done a copy/paste manually. Sometimes it is better to use Excel as a staging platform before pasting it into the new database. You may need to create a temporary table in your new database that matches up exactly with the data you are pasting over. For example, I usually don't put a PK on the temp table at first and make the PK field just an INT. That way the copy will go smoother.
In the corporate world, you would use SSIS to move this data around.
a couple of ways you could do this. One,select everything from each table and save the results as a csv or delimited file (you can do this from sql management studio). You can also script the tables as create and copy the scripts over to the new database, assuming it is a sql server also. Then for import use the load infile statement. You may have to google the syntax for sql server but I know this works in mysql and oracle. haven't tried it in sql server yet.
LOAD DATA INFILE 'myfile'
INTO TABLE stuff
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
SET id = NULL;
Or if you are going to another sql server use the sql export import wizard.
http://msdn.microsoft.com/en-us/library/ms141209.aspx
Hi i am using SQL Server 2008.
How can I import an Excel file into the database, which is the easiest way and simple to do?
OpenRowSet
BulkCopy
Linked Servers
SSIS
I have the above options to Import Excel to Database.
In my opinion SSIS wizard is best way to import excel data where you get row and column wise whole view of table data which will be inserted and also specify column names and contraints and parse data using query.
UPDATE :
If the data in your excel file does not require any processing to match your database table then I recommend you save your excel file as a csv and use a combination of BULK INSERT and the BCP.exe program.
To use BULK INSERT you will need a format file which defines how your datafile matches up to your database table. You can write this by hand to match the existing database table or you can use the following command to generate the format file you need:
bcp [ServerName].[SchemaName].[TableName] format nul -c -f [FormatFileOutputName].fmt -S[ServerHostName] -U[DbUserName] -P[DbUserPassword]
Now you will have 2 files:
DatafileName.csv
FormatFileName.fmt.
Use BULK INSERT within Sql Server to insert your data.
Note: If the columns in your datafile are in a different order than your database table then you can simply edit the generated format file to have them map correctly.