In MS SQL Server 2005, is there a way to export, the complete maintenance plan of a database as a SQL Script? - sql

Currently, if I want to output a SQL script for a table in my database, in Management Studio, I can right click and output a create script.
Is there an equivalent to output an SQL script for a database's maintenance plan?#
Edit
The company I work for has 4 servers, 3 servers and no sign of integration, each one running about 500,000 transactions a day. The original maintenance plans were undocumented and trying to create a default template maintenance plan.

You can't export them as scripts, but if your intention is to migrate them between server instances then you can import and export them as follows:
Connect to Integration Services and expand Stored Packages>MSDB>Maintenance Plans. You can then right click on the plan and select import or export

I don't think you can do that with Maintenance Plans, because those are DTS packages, well now they are called SSIS (SQL Server Integration Services).
There was a stored procedure from which you could add maintenance plans, but I think that it may be deprecated. (sp_add_maintenance_plan). I don't have a SQL 2005 to test here.
The question is, why would you want to export the complete mp? :) If it's for importing in other server, then a ssis package could be useful. I suggest you take a look in that direction, because those you can export/import among servers.

Related

Can you use SQLCMD to generate scripts from 2012 to run in 2008?

I need to take some databases from 2012 back to 2008 and I have done most using the generate scripts method (select 2008 as one of the options and schema and data). When I hit a large database, I get an error about Insufficient Memory to continue the execution of the program. Is there a way to use SQLCMD in 2012 and still pass in the flags so that it will generate a script to be run on SQL 2008? Or any other option or known size limit for using SSMS to generate scripts for large databases?
Thanks for any help,
Mike
This can be done quite easily using the SQL Server Import Export Wizard. If you have special constraints setup on the tables, you may want to create those tables first. The tool is fairly quick and gives step-by-step status updates.

How to create SQL Server Express DB from SQL Server DB

I have a SQL Server 2008 DB. I want to extract SOME tables (and associated schema, constraints, indexes, etc) and create a SQL Server Express DB. It isn't a sync of the target, we stomp on it.
We ONLY need to do this in the file system (not across the wire). We are not fond of the synchronization stuff and at this point don't know how to run SSIS. We are a C# shop and a little code is ok. Like using the C# bulk import stuff, but that won't create the schema.
Suggestions?
My suggestion:
Back up the database
Restore under new name and file
Detach restored database from SQL Server
You now have a standalone file that you could use with SQL Server Express.
We use a tool from Red-Gate called SQL Compare to generate schema-complete SQL scripts. It's about $400, but well worth it. You pick the objects you want (users, tables, views, functions - whatever) you want, and it will generate a SQL Script to re-create them in your new database. Essentially, it's the same as Right-Click -> "Script To... New Window" in SSMS, but all at once, and it has a number of other features your shop might find useful as well.
As Scott pointed out (I couldn't figure out how to comment on his post), you can do a backup and restore, detach and attach from one server version to another assuming that the database is less than 4GB.

Is it possible to restore Sql Server 2008 backup in sql server 2005

Is it possible to restore a backup of a SQL Server 2008 database onto an instance of SQL Server 2005?
I need to work on an sample application for which database backup is in sql server 2008.
But I'll not be able to install 2008. So is it possible to restore that back up in 2005?
No. It is not possible to restore a database from a backup of a newer version.
If you are dead set on it, I think your best option is to selet the database in the Object Explorer in SQL 2008,
right-click, select Tasks->Generate Scripts.In the options dialog emable about everything, including Script Data.
And make sure you select "Script for SQL 2005".
Source
When importing the objects into your target server, if the objects are large you may find that you can't open the SQL file via Management Studio (with a completely useless "The operation could not be completed" error, no less). That's okay, just load the file via sqlcmd.
One important thing is missing in all answers and that is the fact that Generate Scripts in SSMS doesn’t order the scripts correctly.
Scripts have to be ordered in the correct dependency order so that child tables are created after parent tables and such.
This is not an issue for small databases where its easy to reorder the scripts manually but it can be a huge issue when dealing with databases that have 100+ objects.
My experience is that its most convenient to use third party tools that can read backup and generate scripts in the correct order. I’m using ApexSQL Diff and Data Diff from ApexSQL but you can’t go wrong with any popular vendor.
No, not directly. SQL Server 2008 database backups are not backward compatible with SQL Server 2005. However, with SQL Server 2008 Management Studio, you can script data and schemas in SQL Server 2005 mode. This article describes the process in detail.
Yes it is possible
Using the export in the SQL Server 2008. Go to All Programs --> Microsoft SQL Server 2008 --> Import and Export Data
Then SQL Server Import AND Export Wizard window will be opened. Press Next
Choose a Data source (in your case from SQL Server 2008). Choose a Destination( in your case from SQL Server 2005).
Select Copy data from one or more tables or view
Select the source's tables and destination's tables
Click Next & Finish
to complete.
I have had this problem for a long while.
You cannot restore SQL2008 backups onto an SQL2005 instance.
And for me, workarounds like import/export wizzard or to script the database from SQL2008 using the generate scripts with the for SQL2005 option won't work.
Because simply, my databases cross-reference each other inside their views and stored procedures or udfs. They do not befall to my responsibility completely and so I cannot consolidate them into 1 database.
They are a set of 6 dbs that refer to each other directly inside their views and stored procedures.
When I transfer them from one SQL2005 instance onto another, I usually do full-backup/restore.
If I were to script them, even with the with dependencies option I would get errors at re-creation time as db1 will not find views inside db3 because it so happened that I executed the create db1 script first. If I tried db3 first I get similar exceptions.
The only way to script them so that I won't have such dependency exceptions, is to figure out a sequence that works and script them partially in that manner: say: db1_tables followed by db2_tables followed by db2_views followed by db1_views, sp, udfs etc.
I have such a sequence. And when I need to create a new set of such 6 dbs, I executed the smaller partial scripts in sequence.
This explains why the generate scripts, with dependencies and with data and set to SQL2005 version scripts, will just not work for me.
The import/export wizzard is better in my case because it will copy tables and then you still have to script all views, sp, udfs etc.
What I really need is a conversion tool for SQL2008 backup files, to convert them to SQL2005 format. Then my problem will go away.
Or some kind of a tool that would allow restore from SQL2008 full-backup files, without asking me too many questions.
If anyone knows such tools and have used them, let me know.
You can use DBSave, it's a great freeware tool to backup and restore ms sql server on different machines.
It's verry simple to setup and to use.
No you can't, but tools like red gate's SQL Compare/Data Compare can read backup files directly & transfer the info across to a live database, dealing with any syntax or settings that aren't compatible on SS2005
Having had no luck with the Import/Export stuff (flat file exports failed on import claiming charset mapping issues [even though same charset used throughout] and/or truncation issues [even though source and destination had exact same structure]), and having had no luck with using the "generate scripts" option suggested by Garry Shutler (it generated a script with syntax errors), I was finally able to copy the big table I wanted to copy from 2008 to 2005 using the SQL Server bcp utility. So that's another option for this situation, although for an entire database it would be table-by-table and probably doesn't help with views and such.
The steps I used:
On the source server, use "Script Table As...CREATE" to get the structure, run that on the target server.
On the target server, create a bcp format file using your newly-created table:
bcp database.owner.table format nul -f table.fmt -n
(If you're not using Windows auth, you may need the -U and -P options to specify username and password.)
Copy that format file to the source server (if necessary).
Export the data to file on the source server:
bcp database.owner.table out table.dat -f table.fmt
(Again, possibly with -U and -P.)
Copy the data file to the target server (if necessary).
Import the data on the target server:
bcp database.owner.table in table.dat -f table.fmt
(Again, possibly with -U and -P.)
In hopes that proves useful to someone else.

What is the best way to transfer a table or tables from one SQL server to another?

I have been developing in VB.NET and SQL Server 2008 for a while now, but haven't got into live installs yet. In the database system I used be on it had the ability to archive multiple tables into a .dga file, as it was called. I could then restore the .dga file into another database or on another server.
I'm looking for the easiest way to accomplish something similar in SQL Server.
If you want to transfer specific tables, then using Data Transformation Services (right click on the database in SQL Server Management studio and select "Import Data" and it will bring the dialog up for it). Of course, this assumes that you have both databases available to you.
If you are comfortable with replacing the database as a whole, you can easily backup the database and then restore it into a new one through SQL Server Management studio (or through calling the appropriate SP).
I would go for one of the following :
From MS SQL Management Studio, right click on the database / Tasks / Generate scripts
From Visual Studio, in the Server Explorer tab, "publish to provider"
Both will launch a wizard allowing you to export the tables you want the way you want (including data or not, creation scripts or not, etc etc.)
If you want to move tabless without data, the simpliest thing is to script the tables you want and run the script.
We script all our db changes and commit them to subversion and then run them as part of the deplyment process.
If you want to put the whole database on prod including data (scrub out test records first!), then do a backup and restore onthe other server.
For future changes, wescript all our db changes and commit them to subversion and then run them as part of the deployment process. There also are tools that look at the structural differnces bewteen the two servers and creates scripts. REd-Gate's SQL Compare is really good for this.
In addition to HLGEM's suggestions, you can look into SSIS if this is an ongoing process.

How do I backup database from ServerGrid.com?

I have a hosting account with servergrid.com. I want to backup my database, they say I have to use Sql Server Integration Service to backup the database and I would need a commercial version of Sql Server management studio.
I have Sql Server 2005 Developer Edition. I have no idea how to do SSIS backup. I tried playing around with the Sql Server Integration Services Project in VS2005 .. but I failed.
Google also seems to have no step-by-step guide for Non-DBA's like me.
Can anybody point me to/write me a Step-by-Step instructions on how to backup database using SSIS? and also if possible how to restore the database again to the host
SSIS is not really a database backup tool.
If you have a fixed number of tables, you can export the data from SQL Server to comma-separated or raw files - i.e. do the data export using SSIS. It is easy to create such package using SSIS project if you have small number of tables. But if you have a lot of tables it is all manual process. Also it could be hard to automate this - every time you add/remove/change a table or a column, you have to regenerate the SSIS package used to export your data.
SSIS does only data export, so you need a separate tool to do metadata backup (table and stored proc definitions). You can export the metadata using Management Studio (simply script database to text file).
One can call these two tools together a poor man backup tool, but if you metadata changes often you'll probably want to use the real SQL backup tool. Not sure why the hosting guys say you have to use SSIS - maybe they don't want to give you backup permissions to ensure DB safety, but SSIS is not the simplest way to do database backup.
You have a local drive on this machine, correct?
Get access to the sql prompt, through their tools or sqlcmd.
BACKUP DATABASE MYDB TO DISK = 'E:\backups\mydb.bak'
Then FTP that file offsite.
Otherwise, forget these creeps that make you use SSIS to perform tasks that can be done with one line of text.