I copied an SQL folder that contains database info and I would like to add it to Microsoft SQL Server Management Studio. How Do I do this? - sql

Not very familiar with databases, but I have a task where an entire database folder was backed up and copied to a drive on my computer. I have SQL Server installed and Microsoft SQL Server opened. How do I use this folder and its contents as a database?
The folder has the following subfolders
SQL Server -> Backup, binn, DATA, FTData, Install, Jobs, Log, Upgrade and two files: sql_engine_core_inst_keyfile.dll, sql_fulltext_keyfile.dll

For each .ldf+.mdf file sets you have you can restore a database using the following sql. You cannot create the databases in bulk and will have to do them one at a time if you have multiple.
For each .ldf + .mdf combo you have update the dbname and the two filenames
create database dbname
on
(
Filename= 'path where you copied .mdf data file',
Filename ='path where you copied .ldf log file'
)

Related

attach files to SQL operation studio

I have .MDF and .LDF files created by SQL Server. I'm trying to attach them to my SQL operations studio. I have put files in var/opt/mssql/data but the operation studio does not show the files even after refreshing or disconnecting. Is there any other ways to attach?
Databases can be attached using a T-SQL query. Execute CREATE DATABASE...FOR ATTACH from a query window, specifying the desired database name along with the existing file paths with the FILENAME clause. For example:
CREATE DATABASE YourDatabase
ON (FILENAME = '/var/opt/mssql/data/yourdb.mdf')
LOG ON (FILENAME = '/var/opt/mssql/data/yourdb_log.ldf')
FOR ATTACH;
This method can be used with SQL Operations Studio, SQL Server Management Studio, SQLCMD, mssql_cli, or any tool that can run SQL queries.

database restore failing with move

I am trying to restore a database backup but getting error:
Restore failed for Server 'ASIF-VAIO'.
(Microsoft.SqlServer.SmoExtended)
ADDITIONAL INFORMATION:
System.Data.SqlClient.SqlError: File 'C:\Program Files\Microsoft SQL
Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\uwa.mdf' is claimed by
'Aston_Fresh_log'(2) and 'Aston_Fresh'(1). The WITH MOVE clause can be
used to relocate one or more files. (Microsoft.SqlServer.Smo)
When restoring, you need to be sure to
pick a new database name that doesn't already exist (unless you want to overwrite that pre-existing database)
you tick the Overwrite option in the Options tab page and define valid and new file names for the .mdf and .ldf file so that you don't accidentally overwrite another database on your system:
This post has some excellent answers but I don't believe my solution was covered here, or I didn't understand the answer/comment.
However, when I encountered this error I was restoring a database with 2 indexes (Primary and Index). The issue was that when restoring it had created two .ndf files, one for each index, but had named them the same thing.
So essentially I had two "Restore As" files restoring to "D:\MSSQLDATA\DatabaseName.ndf.
To overcome this I had to change one of the file names, so for example I changed
Index | D:\MSSQLDATA\DatabaseName.ndf
Primary | D:\MSSQLDATA\DatabaseName1.ndf
having unique file names fixed this for me.
This worked for me : giving a different name to each MDF and LDF file in the script section.
MOVE N'R_Data'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Build51_Testing_db1.mdf',
MOVE N'R_audit'
TO N'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Build51_Testing_db2.mdf',
etc...
Originally suggested by Alberto Morillo
I know it's long since the last answer, but I happened to search in google for solution for this problem.
What did it for me, was scripting the restore (changing file name did not do the trick) and manually changing the filenames in code
RESTORE DATABASE [DB_NAME]
FILE = N'[name]',
FILE = N'[name1]',
FILE = N'[name2]'
FROM DISK = N'[file_path]'
WITH FILE = 1m
MOVE N'[name]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[name].mdf',
MOVE N'[name1]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[name1].mdf',
MOVE N'[name2]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[name2].mdf',
MOVE N'[logname]' TO N'D:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\Data\\[logname].ldf'
NOUNLOAD,
REPLACE,
STATS = 10
GO
Regards
If you have this issue and it's not the above, try under the Restore Options > Files, check the Relocate all files to folder checkbox.
In my case, there was already a .mdf and .ldf file in my \DATA folder, so I had to create two new files:
New-Item C:\path\to\sql\DATA\NewDatabase.mdf
New-Item C:\path\to\sql\DATA\NewDatabase_log.ldf
And then in the SQL manager you need to select those new files when restoring the database.
In my case, the database has 2 mdf files. And the error came, because I'm trying to restore both mdf files as the same name.
Just rename the second mdf file, under "Restore As".

SQL Server 2000 backup recovering on SQL Server 2005

I've got a SQL Server database backup (file extension .bak) from an project of 12 y/a which I tried to restore on SQL Server 2005.
But this gave me an error that it was not the right version..
So I'm trying to find a SQL Server 2000 version to see if I can restore it with this but I can't find any version that works.
Is there another program to save my backup?
Copied over from msdn forums:
1) Go to restore database
2) Select the database that you want to back up to
3) Locate the backup file on disk. You may have to put it into the MSSQL Server -> MSSQL.1-> MSSQL -> Backup Folder. It must be a .bak file.
4) Select the back that want to restore from the available backups.
5) Go to the top left "options" property and when you do that select "overrite existing database".
6) Now make sure that the path to the files on database to be restored are correct in this same dialog view. Look at the paths to the database file and the log file and make damn sure that they are the correct ones for the database to be restored. The problem here is that those paths are going to be for the filesystem that the backup came from, not the one you are goning to put the restore onto.
Just to add to that, if you are restoring a database to a new server that does not have the database already in it (to restore to), create a sham database with the same name, then restore to it with the overwrite settings mentioned above.

copying sqlserver2000 database from one computer to sqlserver 2008 of another computer

i have a database named SAHS in my desktop having sqlserver 2000 installed i want to copy it in my laptop(64bit) having sql server 2008 ..
i tried removing a backup of it..
like this ;
BACKUP DATABASE SAHS
TO DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\BACKUP\SAHSFullRM.bak'
WITH FORMAT;
GO
can i copy the backup file in my laptop and use the restore statement?.. if yes please show the restore statement im getting error in this :
restore database SAHS
from disk = 'C:...'
saying operating system error.
is there any other simpler way to do so..pls help
Make sure the target server has access to the folder containing the bak file. And on the target server you can try running the Restore Database wizard from SSMS.
i did it myself .Open sqlserver management studio ,from the object explorer expand database column, right click any databse , select task --> restore --> database or Files or Filegroups , restore dialog box opes , write the new name of yor database in To Database , select location and type it in From Device option , select the checkbox , and click on OK ..
ITS DONE .. this is a new feature in sqlserver 2008 ..

SQL Server 2005 backup and restore

I have two backup files
1) is named 'backup.sql' with a bunch of SQL defining TABLES
2) is named 'backup' with a bunch of encoded data, which I believe are the ROWS
I need to restore these TABLES + ROWS, but all I am able to figure out is how to restore the tables.
Any tips on dealing with these files? It's the first time I ever deal with SQL Server.
The backup process would not create a file with actual SQL statements, it would create a binary file. So #1 is not a backup file (it's probably a script someone saved to re-create the schema).
I would try to use SQL Server Management Studio to restore the second file and see what happens. I don't think it will allow you to restore an invalid file, but I would take some basic precautions like backing up the system first.
What is the extension for the 'backup' file? Is the filename backup.bak? If you have a backup file created by sql server then it 'should' contain the logic to create both the tables and restore the data, but it could depend on how the backup was created.
---Edit
It is possible for a .SQL file to contain data values as well as the logic to create the tables/columns for a database. I used to run backups of a MySql database in this way a long time ago...it just is not seen very often with SQL server since it has built in backup/restore funcationality.
Seems unlikely they would export all the rows from all tables into CSV file, and given you said it looks encrypted, it's making me think that's your actual backup file.
try this, save a copy of the "backup" file, rename it to backup.bak and run this from SQL Server Management Studio
restore filelistonly from disk='C:\backup.bak'
(assuming your file is saved on the root of the C: drive)
Any results/errors?