Export Schema and Data in Microsoft SQL Server Management Express - sql-server-2005

How to export a database schema and the data in Microsoft SQL Server Management Express? In other words given a database and the data, I want to create an .sql script that will recreate the table structure and the data inside it.

This can't easily be done within the SQL Express Tools.
If you're willing to look at other tools, have a look at the Database Publishing Wizard from the SQL Server Hosting Toolkit. It's an open-source which will script a database and data into a single script.

Go to:
\Program Files\Microsoft SQL Server\100\DTS\Binn
and run:
DTSWizard.exe
example, mine is:
H:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTSWizard.exe
Thats all

Related

SQL Server Management Studio - Create database with files at specific location

Using SQL Server Management Studio (SQL Server 2008 R2 Express), how do I create a database with files at an arbitrary location, say "K:\SQL_DATA"? I have been able to create it at default location, detach it, move the files, attach it. But it sounds like a lot of unnecessary steps. I would like to use GUI if possible.
You can easily define both the path as well as the actual file name in the Create New Database Wizard:

SQL Management Studio Exporting Data

I currently have a mdf database on management studio and I would like to export the data to a sql file. Exporting the data with the data-source: SQL Server Native Client works fine, but i have no idea where he saved the exported data. Any help?
You need to go in Database->Tasks->Generate Scripts.
Select options there and you will able to generate complete db in SQL Script

Scripting Database schema

I have a database in my sql management studio how can script the database schema to file so that I can put it in another device?
thanks
Open SQL Management -> Script Database As -> .... I think its the closest to what you mean.
Of course there are 3rd party tools for these kind of works. See RedGate.
Shutdown SQL Server, copy the MDF and LDF Files to a new server and attach them on that instance by right clicking on Databases and choosing Attach. Specify the location of the files.
Alternatively, you could also backup the database from the source and restore it in the destination.
The above two methods copy all data too. If you want only the schema, Right click on the database and choose Generate SQL Scripts and follow the instructions.
SQL Management Studio 2008 can make query to unload Schema and data from database, but older versions if Management studio can't do it. You can use another soft to do it like an EMS SQL Management studio

generation of sql queries on tables

I have a few tables in my local SQL Server database with some data in those tables. I want to to transfer that data to my database server. On that server I can run SQL queries.
How can I generate the SQL to do this, or is this possible using SQL Server Management Studio?
First, generate scripts for table structure and run the scripts on your target server, then use the bcp tool (see http://msdn.microsoft.com/en-us/library/ms162802.aspx) to migrate the data.
Take a backup of the database and copy that .bak file to your server, then use restore database option of SQL Management studio to restore the database from that .bak file.
Thanks

Restore SQL Server 2008 DB *to* SQL Server 2005

Got myself in a bit of a pickle here ... working on a CMS project, under the assumption that sql server 2008 was greenlighted as the db of choice. Well it wasn't, we now have to backport all of our content out SQL Server 2008 and into SQL Server 2005.
A simple backup/restore procedure yields: "RESTORE HEADERONLY is terminating abnormally. (Microsoft SQL Server, Error: 3241)".
Unfortunately, exporting the data to an excel spreadsheet yields multiple OLE errors which I believe is actually a problem in the db of the cms.
Does anyone out there have other approaches they would like to recommend for this task? Thanks in advance
Use RedGate:
tool for comparing and deploying SQL Server database contents.
You can work with live databases, backups, or SQL scripts in source control. Damaged or missing data can be restored to a single row, without the need for a full database recovery.
SQL Data Compare helps you compare and deploy changes quickly, simply, and with zero errors...
There is no way to do this by default. You can generate scripts for 2008 database on 2008 server and then execute these scripts on 2005 version. Note that you’ll have to manually review scripts and remove all parts that are unique to 2008 version.
Another way is to use third party tools such as Red Gate or ApexSQL Diff (move schema) and ApexSQL Data Diff (move data).
Use the Generate SCripts to create the database and schema and ensure you target SQL Server 2005 and script data.
Rather than do a backup and restore you might try using SQL 2005's Import/Export Data wizard.
http://support.microsoft.com/default.aspx?scid=kb;en-us;314546
http://msdn.microsoft.com/en-us/library/ms140052(SQL.90).aspx
I've just hit the same problem and here is how I worked around it.
The problem was to copy a database from an operational SQL Server 2008 database to a new SQL Server 2005 database.
I scripted the database using Management Studio on the 2008 server. I only scripted the database design, not the data. I should add also that the DB only has tables and indexes, so I haven't tried this with any cleverer objects although I can't think why they wouldn't work.
On the 2005 server I created a new database by hand and then ran the script to set up all the tables and indexes.
The in Management Studio back on the 2008 server I used the Export Data wizard to export the data from the 2008 server to the 2005 server. It's currently running and seems quite happy moving the data.
Once all the data is across I'll have a couple of small things left to do - create the users and set-up the security in the 2005 DB, but all-in-all it doesn't look like a bad way of doing it. It's not quite point-and-click but it's not too strenuous.
So it seems that the Copy Database wizard won't work (I think because the package ultimately runs on the 2005 server and 2005 Management Studio can't talk to 2008) but the Export Data wizard is quite happy moving data ... as long as the DB already exists on the target server.
Hope that's useful.
It's not possible to restore to previous versions in SQL Server
Is there no SQL 2005 backup around? Otherwise you really are limited to export the entire database in 2008, and re-import back into 2005, or the Import/Export wizard in 2008
Or rely on 3rd party tools. e.g. Red Gate Data Compare is able to sync. the DATA between 2 servers/databases
I only use mysql but can you export your data into sql statments, and then import then into sql2005? Just a thought..
I faced a similar problem (sql 2005 to sql 2000), and found that I happened to have a blank database at the older version. I used bcp.exe to copy all the data.
check this link click here
You can create the database script in sql server 2008 and you can use it sql server 2005 and lower version....