How do I back up a database to a .bak file? - sql

I have a website I've created in Visual Studio 2008 and I need to take it live. How can I backup the database file to a .bak so I can hand it over to the hosting company to place on the server?

From a SQL prompt:
BACKUP DATABASE MyDatabase TO DISK='E:\MyDatabase.bak'

Go to Microsoft Server Management Studio and right click on your database name. Go to "Tasks" -> "Back Up..."
Then assign your properties, ensure that "Backup Type" is full.
Then at the right there is a button "Add" press that and set your filename, ensure that you place the extension .bak at the end of the file name.
Finally hit ok and wait for the backup to complete.
MSDN also has an article that explains this http://msdn.microsoft.com/en-us/library/ms187510.aspx

In ssms right click on the database, go to tasks, click back up. should be self explanatory from there.

You don't need a backup to do so (I assume you are using the AttachDbFilename model that Visual Studio uses by default). Just send them the mdf and tell them to attach it to their SQL server instance.

I assume you use SQL Server. This links will guide you:
How to: Back Up a Database (SQL Server Management Studio):
SQL Server 2008
SQL Server 2005

Related

Microsoft SQL Server 2005 backup the database in *.sql

I work in a small company which is running M/S SQL Server 2005
Now our head office is asking me to give the whole database backup with the table schema in a single file of *.sql
please help me to backup my database in a *.sql including the table schema.
Thanks in advance.
Use SQL Server Management Studio
right click on your database and choose Generate scripts... and hit Next
choose Script entire database and all database objects and hit Next
choose Save to file and enter a path and a file name for your future sql script file. On the same screen choose Advanced and change the Types of data to script property value from Schema only to Schema and data. Hit OK. Hit Next.
and hit Next again.
You can download, install, and use SQL Server Management Studio that comes free with Microsoft® SQL Server® 2012 Express for that
I would go out and download Microsoft SQL Server Management Studio Express.
http://www.microsoft.com/en-us/download/details.aspx?id=8961
It is free. You will be able to connect to the database, drill down into Databases, right click and under Tasks, pick Backup Database. Make sure you pick full...CHoose Disk as the place you want to write it to and Execute...Look thru your options as well...
Hope this helps!
I’d go with the method peterm suggested but note that this also has flaws. Problem is that SSMS doesn’t order the scripts in correct execution order.
For example, it might happen that DDL for stored procedure P is before DDL for table T that is used in P.
All you need to do is to review your script and make sure there are no such cases. If there are you can try fixing this yourself or using some third party tool to generate script that is ordered correctly.

Saving my database?

I'm sorry that I put this question because I think that is simple but I don't know how to do this think because I am a beginner.
I made a database in sql server management studio 2008 express and now I need to send this database to somebody by email.Where is this database saved?
I need to send it with all tables I created and with the diagram.
Should I generate a script or the database is saved somewhere on my computer.
You can take backup of your database and you will get .bak file as a database backup copy then you can mail anyone and they can just restore it to use it.
In sql server management studio 2008 -> Right click on your database -> Task -> backup
To Restore the database right click on Databases then Restore database give the location
of .bak file.

How do you open a detached database in SQL Server 2005

I try to open the database YourGuruDB1 in this directory:
D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data
I go to file and then open file.. Then it tells me, that i must ensure that the database is installed..
Previously I backed up and restored the database, and then detached it..I have no idea where the program dropped the database to..
But I want to open it with all its stored procedures like any other database that i have in SQL Server 2005
If you detached it, you need to attach it.
Just right click on the "Databases" node in SQL Server Managment Server, click "Attach", navigate to the data file you indicated, and tell it to attach the database.
You have to attach back the database.

SQL 2005 Moving from Godaddy SQL Server to a company owned server

What is the best way to go about moving a database from a Godaddy SQL 2005 account to a local SQL 2005 server? I have access to the DB through Server Management Studio Express and also through the Godaddy SQL explorer.
However, I have no idea where to start. In MySQL, I would just export the data through the PHPMyAdmin page, and conversely import it on the other server using an ASCII file. In access, I'd just use the migrate tool. In Server Management Studio, I've thought about using the "Backup" and "Restore" method, but I'm afraid that I won't have the ability to create a new object with the correct permission schema on the new server.
What are your thoughts? Keep in mind that I do not have access to the MDF or temp files. I've been studying this page.
SMSS should be able to do it for you. If you are looking to move the entire database and not just a few tables, the Backup and Restore method is probably your best bet.
Your steps might include:
connect to Godaddy sql server in ssms
Right click the database you want to move and select Tasks > Backup
Keep/set Backup type = "Full" and add a destination at the bottom that you will be able to access.
After backup completes, move the .bak file to a location that your local sql server can see.
Connect to your local sql server in ssms.
Right click Databases > Restore Database
Enter the database name you want in "To Database:"
Select "From device:" and locate the .bak file you created before.
In the row that shows up in the grid display, check the restore check box.
If it matters to you where the recreated files will be stored, select options on the top left menu and confirm the file locations under the "Restore As" column in the data grid.
Click ok and the restore should start.
To migrate users, follow the directions at http://support.microsoft.com/kb/918992
Don't be so afraid of the backup and restore. You have a much better chance at getting a high fidelity copy of your data than trying to roll your own. Give it a shot, test it out, and see what happens. I think you'll be pleasantly surprised.

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