save the whole database to a query in sql server 2008 - sql

I'm trying to save the whole database to a query in sql server 2008. I have experience with mysql and phpmyadmin, and over there I used to have a simple button to save the database, including constraints and basically everything, to a simple query.
that query basically recreates the database i created just as it was. I think you guys understand what I mean.
is there such an option in ms sql server? thank you in advance.

You can generate scripts to recreate the database structure in SSMS:
Right-click a database, choose Tasks > Generate Scripts... and go through the wizard.
You do not get insert scripts for all the data by default, you need to choose that in the Advanced options in the wizard, Types of data to script choose Schema and data/Data only/Schema only`

For SQL Server, I generally go with a backup/restore point of view. You can backup your entire database to a file, and then choose to restore that database (To another name as I often use for recreating new test databases).
I don't know about creating a query out of the database, but the effect of both seems to be the same result.

Related

SQL Server: dump/export database indexes

I got a SQL Server database which I would like to dump, but only indexes and maybe structure, but I couldn't figure it out how.
I use SQL Server Management Studio, but I cant see how would I do this. MySQL is much more easier then this :)
Any tips or how-to's would help.
NOTE: I'm new to SQL Server.
Right click database ->click on generate scripts --->Choose Script Entire database
In new window,click on Advanced and choose types of data to script as Schema only ..you can play with another options
now complete all the screens and you can see structure of all tables and indexes..

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 Server 2008 scripting wizard not creating database

I want to use the scripting wizard in SQL Server 2008 to generate a copy of the whole database
It seems to have worked before because I have generated scripts including both the CREATE DATABASE and CREATE TABLE statements, but now I am only getting the CREATE TABLE scripts.
I know I can script creating the database separately and chain the statements together, but have I missed an option that automatically includes the CREATE DATABASE script?
Thanks
if you choose the option "Script entire database and all database objects" in the wizard. database creation is part of the script.
And in the advanced section i don't see an option to exclude Database creation.however there are lot of other things you can configure there.
I know its very late to respond to this question. I faced this issue recently. There is an option in the advanced section "Script Database Create" which will be false by default. Make it as true and it will add create database script also. Thank you.

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.

What is the best way to transfer a table or tables from one SQL server to another?

I have been developing in VB.NET and SQL Server 2008 for a while now, but haven't got into live installs yet. In the database system I used be on it had the ability to archive multiple tables into a .dga file, as it was called. I could then restore the .dga file into another database or on another server.
I'm looking for the easiest way to accomplish something similar in SQL Server.
If you want to transfer specific tables, then using Data Transformation Services (right click on the database in SQL Server Management studio and select "Import Data" and it will bring the dialog up for it). Of course, this assumes that you have both databases available to you.
If you are comfortable with replacing the database as a whole, you can easily backup the database and then restore it into a new one through SQL Server Management studio (or through calling the appropriate SP).
I would go for one of the following :
From MS SQL Management Studio, right click on the database / Tasks / Generate scripts
From Visual Studio, in the Server Explorer tab, "publish to provider"
Both will launch a wizard allowing you to export the tables you want the way you want (including data or not, creation scripts or not, etc etc.)
If you want to move tabless without data, the simpliest thing is to script the tables you want and run the script.
We script all our db changes and commit them to subversion and then run them as part of the deplyment process.
If you want to put the whole database on prod including data (scrub out test records first!), then do a backup and restore onthe other server.
For future changes, wescript all our db changes and commit them to subversion and then run them as part of the deployment process. There also are tools that look at the structural differnces bewteen the two servers and creates scripts. REd-Gate's SQL Compare is really good for this.
In addition to HLGEM's suggestions, you can look into SSIS if this is an ongoing process.