SQL Server Management Studio - Create database with files at specific location - sql

Using SQL Server Management Studio (SQL Server 2008 R2 Express), how do I create a database with files at an arbitrary location, say "K:\SQL_DATA"? I have been able to create it at default location, detach it, move the files, attach it. But it sounds like a lot of unnecessary steps. I would like to use GUI if possible.

You can easily define both the path as well as the actual file name in the Create New Database Wizard:

Related

Generate Scripts in SQL Server (big files)

I am in process of moving my database from SQL Server 2012 to SQL Server 2008. Since I can't just restore them like if I was moving from 2008 to 2012 I have to use generate scripts for data and schemas.
Problem is I have some HUGE database files. One of the files generate becomes 19gb. There does not seem to be any way to move this file because I think the size itself makes the file corrupt. I cant open the file in the SQL Server Management Studio and even using the .bat script it fails (it just freezes). My other tables I have no problem with but they are much much smaller.
What could fix this would be if there was a way to split the data up in several files like each file is 100mb or whatever, then I could make a script that would execute them all, but is this possible?
If not what do you guys suggest?
I would suggest you create a database with the same name in SQL Server 2008 (and possibly tables) and try to do a replication between the two database with SQL Server 2008 as the subscriber, just once should do
If you have the ability, you could also try creating a linked server entry on the 2008 box that points to the 2012 one. Then, you can use the four part fully qualified name (server.database.schema.table) to SELECT the rows from the 2012 instance and INSERT them into the 2008 instance.

How to copy architecture of an existing database to a new database in SQL Server

I'm using
Microsoft SQL Server 2012 (SP1) - 11.0.3153.0 (X64) Express Edition (64-bit) on Windows NT 6.1 (Build 7601: Service Pack 1) (Hypervisor)
and I need to copy the database architecture(Tables and their constraints) to a new database so I can extract the database diagram. The current database won't allow me to(extract a diagram), but any new database I create, will.
I tried creating one with the old ones mdf but it threw an error.
I tried to do an export, which copied all of the tables, but none of the constraints!!!
In SQL Server Management Studio, right click on your database, select Tasks, Generate Scripts. Select the options for generating tables, indexes and constraints. Use the generated script(s) to recreate a new database where you can create the diagrams.
Management studio->Right click on the database
Task->Generate script->Script entire database and all database objects
generate the script to a file/clipboard/new query window
Create new database schema from this script
If you have access to (friendly) developer they may have a copy of MS Visual Studio with SQL Server data tools installed; in it there is a handy feature called SQL Schema Compare that can copy whole or parts of schemas between databases.

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

How to create SQL Server Express DB from SQL Server DB

I have a SQL Server 2008 DB. I want to extract SOME tables (and associated schema, constraints, indexes, etc) and create a SQL Server Express DB. It isn't a sync of the target, we stomp on it.
We ONLY need to do this in the file system (not across the wire). We are not fond of the synchronization stuff and at this point don't know how to run SSIS. We are a C# shop and a little code is ok. Like using the C# bulk import stuff, but that won't create the schema.
Suggestions?
My suggestion:
Back up the database
Restore under new name and file
Detach restored database from SQL Server
You now have a standalone file that you could use with SQL Server Express.
We use a tool from Red-Gate called SQL Compare to generate schema-complete SQL scripts. It's about $400, but well worth it. You pick the objects you want (users, tables, views, functions - whatever) you want, and it will generate a SQL Script to re-create them in your new database. Essentially, it's the same as Right-Click -> "Script To... New Window" in SSMS, but all at once, and it has a number of other features your shop might find useful as well.
As Scott pointed out (I couldn't figure out how to comment on his post), you can do a backup and restore, detach and attach from one server version to another assuming that the database is less than 4GB.

Export Schema and Data in Microsoft SQL Server Management Express

How to export a database schema and the data in Microsoft SQL Server Management Express? In other words given a database and the data, I want to create an .sql script that will recreate the table structure and the data inside it.
This can't easily be done within the SQL Express Tools.
If you're willing to look at other tools, have a look at the Database Publishing Wizard from the SQL Server Hosting Toolkit. It's an open-source which will script a database and data into a single script.
Go to:
\Program Files\Microsoft SQL Server\100\DTS\Binn
and run:
DTSWizard.exe
example, mine is:
H:\Program Files\Microsoft SQL Server\100\DTS\Binn\DTSWizard.exe
Thats all