I'm brand new to SQL and I'm practicing some queries with a DB.
I've now just detached the database using Tasks > Detach
Question 1: When I detach a file, I'm guessing it's saved to an MDF file? Where would I locate this file?
Question 2: When I create a new DB, where do the related files get saved? I'm assuming an MDF and an LDF set of files are created.
If it helps, here's my version info
Microsoft SQL Server 2008 (SP1) - 10.0.2531.0 (X64) Mar 29 2009 10:11:52 Copyright (c) 1988-2008 Microsoft Corporation Developer Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1)
Thanks!
You can always look at the database properties in your Object Explorer in SQL Server Management Studio before detaching - the file(s) will not be moved or anything when detaching....
In the Properties dialog box, go to the Files section and to your right, the relevant info can be found:
SQL Server databases are .mdf files. When you detach, the .mdf file is closed by the SQL Server process, but it exists from the moment you create the database. Just to be clear, there is no concept of "saving" in an SQL DBMS; at least, not in the sense you are suggesting. Every transaction you perform is permanently stored from the moment it is committed.
When creating the database, the dialog box shows a list of files that will be created. You may have to resize some of the columns and scroll horizontally to see the full path. You can also see this information by bringing up the database properties dialog.
The .ldf file is the transaction log. It plays a vital role in ensuring the permanency of committed transactions.
Ok so if you have already detached the database, and then realized that you are clueless where it is, you can do this trick.
Expand server, then on Databases click Right Mouse then choose Attach...
Click Add...
Then in the new window that opens will be a path to the directory where your detached database is (if you haven't navigated from default location earlier)
Also, the default location for MSSql databases is:
C:\Program Files\Microsoft SQL Server\[YourSQLVersionGoesHere]\MSSQL\DATA
Hope this saves you some time.
Related
I have a backup file which is over 150gb. I am trying to create a new database from a backup. But it failed with the following exception:
Create Database or Alter database failed because the resulting cumalative database size
would exceed your licensed limit of 10240 MB per database
As there is restriction of max 10 GB for SQL Server Express, is there any way to create only the schema (stored procedures, functions etc) from the backup file, and not the data.
No, there is no "schema-only" restore. But you have several other options:
Download and install an instance of Evaluation Edition, restore your database there, and extract the things you need. Then uninstall the instance of Evaluation Edition.
Buy Developer Edition and use that, permanently, instead of Express. You should be able to find this at your favorite software retailer. Amazon has it for $43.99; Microsoft has it too but they charge full price ($59.95).
Try out some of these 3rd party tools that let you "attach" a backup as if it were a database (Red Gate has one; Quest may also have similar functionality with LiteSpeed). With Express Edition though it may be subject to the same size limitation, I haven't tried, and I'm not sure if the trial editions of those products have any limitations either.
To create a database with an empty schema I can suggest two options:
1) In SSMS, right click on the database in the Object Explorer, go to Tasks/Generate Scripts and run through the wizard to generate a sql script to create a new database with the same schema.
2) Use Red Gate SQL Compare, put the database in the left hand side data source, and select 'Create Database' on the right hand side of the comparison. Run through the comparison and Deployment Wizard to create a new database based on the schema of the source database.
I know this is an older question, but it popped as the first result in a search for me. SQL Server Developer edition is now free through Visual Studio Dev Essentials. You can download 2017 Developer here for all your large database needs!
This question already has answers here:
Management Studio default file save location
(16 answers)
Closed 8 years ago.
As the title states, how do I do this?
I want to hit save, and have SSMS automatically direct me to a network folder..
This is 3 years old now, but an answer for SSMS 2012 and 2014 would be helpful, so I thought I'd add an update. Step one differs between the versions, and then the rest is the same:
SSMS 2012
Locate C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\Extensions\Application
SSMS 2014
Locate C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\Extensions\Application
Both (continued)
Open ssms.application.pkgdef with text editor(e.g. Notepad)
Change the value of DefaultProjectsLocation
"DefaultProjectsLocation"="$MyDocuments$\SQL Server Management Studio"
Save the file
Thanks to this source: http://www.networksteve.com/forum/topic.php/How_to_change_the_default_query_save_location_in_SSMS/?TopicId=41425&Posts=0
The correct location for 2k8 in the registry is HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell.
It's not editable from within the tool (for some reason), but you can adjust it from the settings file within My Documents > SQL Server Management Studio > Settings.
Look for the node "ProjectsLocation", and adjust accordingly -
<PropertyValue name="ProjectsLocation">\\mynetworkpath</PropertyValue>
Be sure to exit SSMS before editing this file. This should do the trick...
#Kevin's solution doesn't work for SQL 2k8. One needs to change the registry:
key = HKEY_Current_User\Microsoft\Microsoft SQL Server\100\Tools\Shell
Now see where they wrote the default path... change that into any valid UNC.
This seems to work for me after a lot of bungling -
Edit registry settings as outlined in above posts (HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell) - change all the paths EXCEPT MyDocumentsLocation (this is what seems to cause the settings to get reset).
Locate the .vssettings file from My Documents and copy to your folder + '/Settings' folder (e.g. c:\Dox\SQL Server Management Studio\Settings).
Start SQL studio, quit and restart.
Edit the .vssettings file (should be in your folder now rather than My Documents), and change the ProjectsLocation to the desired folder e.g. C:\Dox\SQL Server Management Studio\Projects
Start SQL studio. Opening files should now work, but save will require clicking the 'My Projects' on the left of the save dialog.
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.
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
I just installed VS 2010 for the purposes of running someone else's DB project that was created using the 2010. In VS 2008 I was able to right click on a SQL file ans select "Run ON" to run the script on a given SQL Server. I don't see this option in 2010. Is it available and if so how do I get access to it?
The database project format that was included in VS 2005 and VS 2008 has been completely removed in 2010.
Rather than holding loose SQL files that could be run independently, it acts a bit more like a compiler. When the project is built, the SQL files are parsed and (for the most part) turned into an XML-description of the database schema.
If you're trying to create or update a database based on all of the scripts in the project, right click on the project name in Solution Explorer and select "Properties". Under the Deploy tab youchange "Deploy Action" to "Create a deployment script and deploy to the database". Specify the connection settings and database name.
When you select "Deploy" on the right-click context menu of the database project, Visual Studio will build the database deployment files and generate the database. It's generally intelligent enough to update existing databases as well, assuming the project was designed well.
If you're attempting a remote deployment to a production SQL Server, things get a bit trickier. There is no single set of SQL files you can run - part of the database schema is stored as XML.
Take a look at Link - it describes how to use the "vsdbcmd.exe" utility to deploy a database file.
If you just want to run a single SQL file or test part of one, open the file, right click, and select "Execute SQL"
DNRTv # 167 talks about VS 2010 Database Projects in detail.
As #ShadowChaser already mentioned, DB Project in VS 2008 simply had the scripts in it, and 2010 version is a lot more complex and has a lot more features.