Restore SQL database from disc copy backup - sql-server-2008

I have managed to drop an SQL express 2008 database, that I accessed using SQL Management studio.
I don't have a backup of the database created through Management Studio or SQL, but I do have a disc copy of my entire c: drive made prior to a machine rebuild 4 weeks ago (A previous installation of the dropped database did exist at this stage). The disc backup contains all the databases (2) and versions, that I require.
Can I restore the databases from copies of raw files form a backup disc? If so is this complicated?
Which files would I need to be copy and to where?
Thanks in advance. Your help is appreciated.

Should be pretty easy:
(if needed) re-install SQL Server (Express) - you should make sure to install the version with the Management Studio
Copy the "raw" files (*.mdf and *.ldf) to the default data directory
In SQL Server Management Studio (Express), in the Object Explorer, go to the Database node and right-click and pick Attach...
Find your *.mdf file in question and select it
That should be all there is!

If you have the old .mdf and .ldf files you can use the "attach database" option rather than restore.

Related

Create MySQL database from .mdf and .ldf files from SQL Server 2008

I have some .mdf and .ldf files of database size greater than 10 GB with me.
I want to create a MySQL database using the same.
Is there any provision in MySQL to do it?
Please consider that MySQL and SQL Server 2008 can not be installed on the same machine (or even the same network) in my current setup.
I don't have enterprise edition of SQL Server management studio in our network and will not be able to install it.
Is there any other elegant way to export data from SQL Server 2008 and import it in MySQL?
I don't think it is possible without attaching.
If you find a way how to attach it, you can use some specific migrating tools like this.
Some tools allow to create database specific queries from another solution, that need to be only executed on your side.
The MDF and LDF files belong to Microsoft SQL Server and use Microsoft's own binary format, so you cannot connect these files to other database management systems. The only approach I can think of, is to script out the database code and data from the SQL Server database to a text file (.sql file), and import this file into MySQL.

How to transfer local sql server or database to another computer

I'm working on a project with 4 other guys, and we are developing an android app with a DB. Now, we are going to use a localhost for our SQL Server, I want to be able to take the database from my laptop and copy it to the other guys' computers. I"m using SQL Server 2008 Management Studio.
Any ideas of how to do it? I don't mind to copy the entire localhost server if we can do that.
BTW, I tried to backup the DB on my laptop by right-click on the DB (created .bak file) but there is no restore option on the other computer.
Thanks
Backup your data base and restore in the other machines
edit
If you dont find the restrore option, please try using sql script
ex:
RESTORE DATABASE nwind_new FROM DISK = 'c:\backups\northwind\nwind.bak'
WITH
MOVE 'northwind' TO 'd:\Program Files\Microsoft SQL
Server\Data\nwind_new.mdf'
MOVE 'northwind_log' TO 'd:\Program Files\Microsoft SQL
Server\Data\nwind_new_log.ldf'
You can try
See these links about backup and restore:
http://technet.microsoft.com/en-us/library/cc966495.aspx
and
http://blogs.msdn.com/b/sreekarm/archive/2009/09/11/move-a-database-from-one-server-to-another-server-in-sql-server-2008.aspx
To restore your database see this useful link:
http://msdn.microsoft.com/en-us/library/ms177429(v=sql.100).aspx
its weird you dont see the restore option. You could try deattaching the DB from its location, copy the files (DB and LOG) to the new location and attach it there.
MSDN

Convert a .bak file to .sql file

I have a asp script that I'm intending to write it with PHP so I have to get its database and use it.
I have the database as .bak file which I understood that it's a backup and I wanna change it to be .sql to import it in phpMyAdmin
I read about this matter in the web but I didn't find an accurate tutorial that goes through the whole process.
They are talking about mssql database but I didn't even reach this step..
Any help will be highly appreciated. Thanks in advance :)
Note, all of this applies to MS SQL because .bak is a usually a MS SQL backup.
A .bak can't be converted to SQL directly -- it contains a backup of a database which does not have a clear relationship to SQL.
You could restore the backup and then use SQL Server tools and then use that to make some SQL to recreate the SQL server objects but not the dat.
From SQL Server Management Studio: Datbases item, right click "Restore
Database" then from datbase right click script database.
This won't script the data.
The other option is to use RedGate's excellent tools, which should do everything you want.
http://www.red-gate.com/products/sql-development/sql-toolbelt/
Most probably the .bak file is indeed a binary backup of a Microsoft SQL Server database (which is something completely different than MySQL).
So you will first need to install Microsoft SQL Server (Express) together with the SQL Server Management studio (I think there is a bundled download "SQL Server Express including Tools".
In the Management Studio you can then import the .bak file into a new database. Once the import is finished you can use it to create SQL script out of the database.

Can we restore database backup of SQL Server 2008 R2 Express to SQL Server 2008 Express

I have a database backup in "SQL Server 2008 R2", Can i store this database backup in "SQL 2008 Express" ?
Anyone who have knowledge about SQL-2008 kindly share to me.
No and 'yes'.
A backup (.bak) is not possible, nor is copying .mdf over but you can downgrade.
You could go back to 2005 if you wish to.
I found this information which runs you through it the easy way.
How to Downgrade SQL Server Database
Direct link: http://www.mytechmantra.com/LearnSQLServer/Downgrade_SQL_Server_Database_P1.html
TIP: Use Microsoft OLEDB connector to destination instead of the native client and you should avoid any errors in the transfer
Nothing is impossible, you just have to get creative :)
Install an instance of SQL 2008 R2 on one machine and SQL 2008 on another
Open SQL Server Management Studio R2
Select your source Database
Select Tasks>Generate Scripts.
Select 'Script entire database and all database objects', press 'Next'
Select 'Save to File' and click on the 'Advanced' button
Select 'Script for Server Version' and select the version you want: 200/2005/2008
Select 'Type of data to Script' and select Schema/Data/both
Click 'OK',Next and do it!
Copy the resulting file to the target machine with SQL 2008 [or whatever]
Log onto your SQL Management Studio and open the copied .sql file... be aware that there may be limitations on the file size.
There may also be issues with the order that the .SQL file inserts the data into the target database and if there are FK constraints in place, this could be an issue.... simply re-order the insert lists.
Once the .sql file is organized, parse it [just to sure], and then execute.
Let me clarify a little on these directions.
On the SQL Management Tools be logged into both the old and the new server if possible.This makes these steps even easier.
So, start with the source server, right click on the database and script it. There is one option called ‘Script Data’ that is off by default, we set it to true so the script will include inserts for all of the data. We choose to script the tables, views, indexes and keys (and triggers … not sure if you use any of those). I also did not mess with the users, since that is problematic. It is easier to create the user by hand once on the local SQL server and give them permissions to the dbs.
Then script the DB to a file.
Then select the local SQL server and add the database by hand, then open up the script file and execute it under the new database, all the tables, data, indexes, etc came over just fine. Setup the user permission and you are golden.
NO, you cannot do this.
There is no way, no method, no hack, no workaround, no trick to get a backup from a more recent version of SQL Server back into an older version.
It just doesn't work - it's not supported.
You'll need to synchronize your structure using some kind of SQL diff tool, and possibly your data by exporting and importing, e.g. via the "Data Export / Import" wizard or some custom way.

Where to download AdventureWorks2008.msi?

I'd like to install AdventureWorks2008 (I just install SQL Server 2008 R2 Express).
Each time I download the recommended version from CodePlex, all I get is a AdventureWorks2008.mdf file. Not only I cannot attach the file from SQL Server Management Studio, but I cannot copy/paste the file directly into the the database.
I've read in several places that I need to use AdventureWorks2008.msi, but I cannot find where to download it.
I just cannot figure out how to install AdventureWorks2008
Thanks for helping
There isn't an .msi file for adventureworks, even though you'll find it mentioned in outdated documentation and books. You aren't alone in finding this confusing -- it seems the web site, files and steps Microsoft provides for installing these databases changes every time I need to install them.
You need to create the database and attach the .mdf file, which is the "data file" referred to in the instructions. (.mdf = primary data file, .ldf = log file, .ndf = secondary data file)
In order to attach the file, you need to make sure you carefully follow the steps here: http://social.technet.microsoft.com/wiki/contents/articles/3735.sql-server-samples-readme-en-us.aspx#Readme_for_Adventure_Works_Sample_Databases
Instructions for 2008R2:
To install AdventureWorks2008R2 OLTP database
Download the AdventureWorks2008R2 Data File.
From File Download, click Save and browse to a location on your local
server.
From SQL Server Management Studio, execute the following code:
Case-insensitive Database
CREATE DATABASE AdventureWorks2008R2
ON (FILENAME = '{drive}:\{file path}\AdventureWorks2008R2_Data.mdf')
FOR ATTACH_REBUILD_LOG;
As an alternative to step 3, you can attach the database using the SQL
Server Management Studio user interface. For more detailed
information, see Attach a Database (SQL Server Management Studio).
Note: You must remove the log file from the list of files to attach.
This will cause the operation to rebuild the log.
Headache saving tip from Aaron Bertrand:
You should place the mdf file in your normal data folder - SQL Server
will already have the proper permissions. You can get this path using
SELECT TOP (1) physical_name FROM master.sys.database_files;
You can directly paste that file into your database directory. For more information you can refer http://tryingmicrosoft.com/error-while-attaching-a-database-to-sql-server-2008-r2/.