Taking a SQL Database with me for a presentation - sql

I am a beginner with sql and tomorrow I have to turn in my first assignment, which is a simple, small database. The thing is I don't really know if I can just find the database in my computer, copy it in a usb drive and then just plug it in another pc so it can run there.
Can you please tell me if that's the way it works or if I should do something else?
Thanks a lot.
By the way, I use sql server express 2012. If you need to know anything else, just ask. :)

I'm not fan of Attaching and Detaching databases as this leaves no backup on the localdisk but rather just use BackUp and Restore feature.
To Backup:
right click database to which you want to backup
click Task
and select BackUp
fill-in Name and add the Destination
To Restore:
right click Databases
a popup will appear and click Restore Database...
Other Link
Backing Up and Restoring How-to Topics (SQL Server Management Studio)

Related

How to unlock a Database.mdf file so can share with friends?

Does anyone know how to unlock a SQL Server .mdf file so can share with friends?
Because the file that my friend share with me for our group assignment happen to be locked up and that I can't use the data within and only can view it.
Actually I want to share my database with my partner in this group assignment. We use a similar database. However, due to reason of time meet up with our instructor, we both need to have our own holding of a database for presentation at different time.
Also the reason, I want to learn to unlock it is because, we may need to try in on different hardware as well. Is in by Exporting? Like what is shown in this link video? https://www.youtube.com/watch?v=c2XmaCFk-kk
Firstly, to be able to use .mdf/.ldf files in common operations like Copy/Paste you need:
1. Under Sql Server Management Studio right click on the DB:
2. Then under Detach window check 'Delete Connexions' and click Ok:
You're free to do whatever you want with your .mdf/.ldf files
You probably shouldn't be sharing the MDF files, but if that's what you want to do you will indeed have to detach the database and transfer MDF and LDF files before attaching it on the other side.
It's not completely clear what you want to accomplish, but I think your best option is to take a backup on your machine, transfer the backup to the other machine and restore it there, that way the database doesn't have to go offline.
See this link for a how-to on the backup/restore method.
See this link for instructions on the detach/attach method
Share SQL connection, not the MDF file. Use SQL Surface to enable network access to your DB and define user logins.

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.

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.

What is the most efficient way to restore multiple databases in SQL 2008

I'm in the process of doing a large scale server migration, as such I have to move 50+ SQL 2005 databases to a new SQL 2008 server installation.
The DB guys have only given me a backup of each database, so I have a directory with some 50 .bak files sitting in a directory (ie c:\db) that I need to restore.
I need to restore each database to the new server.
I can do this individually in Management Studio, but that would be time consuming. Is there a more efficient way of solving this problem.
So my question is:
What is the most efficient way of restoring all of these databases.
Machine background:
The server is Win 2k8, with SQL 2008 Workgroup Edition, .net 4 is installed along with Powershell 2.
Thanks in advance.
Edited after comment: you can script restores, like:
restore database DatabaseName
from disk = N'c:\dir\BackupFileName.bak'
with file = 1,
move N'DatabaseName' to N'c:\dir\DatabaseName.mdf',
move N'DatabaseName_log' to N'c:\dir\DatabaseName.ldf',
stats = 10,
recovery
The two move lines move the files to a location on the new server. Usually the names are DatabaseName and DatabaseName_log, but they can vary.
With recovery means: bring database online without waiting for additional log restores.
To generate a script like this, click the Script button (top left) in the Restore Database wizard window, and click Script action to....
Write a custom application/script? You could extend SSMS or use SQL server tools to write an application that just reads these files and restores them to the database. I know it is possible in .net, might be possible using powershell scripts as well.
This is efficient if this task is to be done in a short period of time during the production migration, otherwise the overhead of writing the app is more than doing 50 restores manually! But if you are a developer and you choose manually, then shame on you! :).

How do I back up SQL 2008 tables & stored procedures?

Last night I got completely hosed by a worm from Dilbert.com (so be careful there). It is invasive enough where I am going to do a complete system restore. The only thing I need to save on the pc is a database (consisting of just tables & stored procs) in SQL 2008. How can I export them so that, once I restore, I can easily import them again. I thought about doing Access, but that is never completely clean (data types get changed and such).
You should just be able to back up the database from within SQL Server Management Studio. Right-click on the database in the Object Explorer and use the context menu to begin a backup operation.
In addition to the backup operation, which restores everything, you can also use the Generate Scripts option in SQL Server Management Studio to create a text dump of all the tables, keys, stored procedures, users, and so on. This option is available by selecting your database (left click once), right click to get the option menu, then choose "Tasks" (which opens a new submenu) and then "Generate Scripts...". Note that the Generate Scripts wizard is NOT the came as the "Script Database As" option. The "Script Database As" option is very limited, and won't give you many of the database entities you need for a complete restore of the schema.
Alternatively since you are going to take the machine down anyway, just detach the database. Then you can copy the file to an external hard drive or another machine.