Creating a blank copy of a SQL Server 2012 database on the same Instance - sql

I'm trying to determine the best way of creating a blank copy of a SQL Server 2012 database, renaming it & placing it on the same server instance. I could restore/rename a backup copy, and then delete all the data, but there are quite a few tables/views, stored procedures, triggers, etc.
Are there any drawbacks with the "generate scripts for database objects" wizard? Just trying to figure out the most efficient way to create a blank copy & would appreciate anyone's experience/wisdom on the topic.
I am running a SQL Server 2012 Enterprise edition. We have a database that our colleagues like, so we are planning to create a copy & populate with their data instead of our data.

Go to Object Explorer ,Right Click the database you want to create a blank copy of.
Right Click --> Tasks --> Generate Scripts
Select the entire Database, you also have the option to select specific objects, In advance option select schema only.
I would prefer this method over any other, as Restoring a Copy of database and then deleting data means doing a lot of work which was never required to begin with. Backing up data that was never required, restoring unwanted data and then finally making sql server to delete it, a lot of unnecessary work.
Another reason why scripts are better over other options, These scripts will use fresh pages to write all of this data. Imagine you having to write something on a brand new note book as compare to a note book where you had to erase first and then use it to write data on it.

Related

Some useful functions of MySQL Workbench for SQL Server management studio

Our project is moving from MySQL to MS SQL and after a long time working with MySQL Workbench I really miss some features in SQL Server Management studio (2014).
Do you know whether they exist in SSMS or there is an alternative/replacement application for SSMS to work with database?
Functions are listed below:
Generate update data script to review and to be able to copy-paste it. Do not update data when I move to another row when the table is opened for editing.
Some changes are still made in database in our project, and sometimes it's easier to add some rows manually in 5 tables, get the script, test it and run the script at production environment. I don't want to write a script for each update and I don't want to make a mistake when copying data to production server using edit table option.
Review update table script BEFORE the changes were made, not after (I am talking about Tools - Options - Designer - Auto generate change scripts).
Upload a file using select file dialog into a binary field.
Again, I know about using OPENROWSET function, just interested how to do it as I used to.
Ability to view large text fields in a convenient way in SSMS. Now I have to copy data from a field and paste it into notepad. (For example, error message with a long trace log)
Save a few tabs with some useful scripts and open all of them when I open SSMS.
Is there any way to organize tabs to be able to work with 10+ tabs more effectively? Now only 6 of them can be shown on the screen (compate it to 15 tabs in MySQL WB).
Simple 'search field' (like Ctrl+F in Excel) to be able to search data in all fields displayed on the screen.
I would appreciate any ideas.
Thank you.

How do I add records from an Access database into an existing SQL Server database?

I have an existing Access database that has out grown it's usefulness. I have written a Visual Basic program that uses a SQL Server database and have been re-entering the data from the Access file into SQL Server individually.
I still have 300+ records to move and would like to find a way to do all this using either a data snippet in Visual Basic, or using SQL Server Express. I'm smart enough to set up and use Access, and smart enough to create a program and database in Visual Basic and SQL Server but for some reason I not smart enough to move the records between the 2 databases.
When I originally created the .mdf file I attempted to move the records at that time but everything I tried didn't work so I figured I'd get it later, but now I have 300+ records in the .mdf file and need to get the others moved over. Anybody have any ideas?
Easiest thing to do is create your database, then in SSMS's Object Explorer, right click on the database, Tasks -> Import Data ... and go through the Import/Export wizard, selecting MS Access as your source.

save the whole database to a query in sql server 2008

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.

Is there a special sp on SQL server 2008 to get a table change script?

I wonder how management studio generates the change table scripts each time i change a table, especially when i change the datatype from 'text' to 'varchar(max)'.
Peace,
Ice
Update: Concerning the already given Answers i want to precise my question, after say thank you for your posts.
Now, it is like already said, ssms generates the scripts on demand but i want to write a script to identify all the tables in a given database with datatype [text] and change them to [varchar(max)]. So the easy part is to scan the dictionary to find the tables and columns, the harder part is to generate the mentioned scripts which copies all the rows into the new structur.
--> Yes i can work manually thru the list of tables and click in ssms to get the scripts, but there are almost 200 tables... better a computer do that work, isn't it?
If what you're asking is "Given a table, is there an easy way to get the DML used to create that table?" then I don't believe you can just run a system SP and get it. You'd need write something that selected from the system tables to get columns and datatypes, indexes, and everything else.
I wish there was an easy way to generate the same scripts SSMS does (like right-click -> "Modify" on a stored procedure), but it doesn't seem to be that easy.
When you change a table using the Management Studio table designer, the script is already prepared in the background, and you can simply click on the "Generate change script" icon to view it (and copy it if you like).
In SQL 2008, the "Generate change script" option is in the "Table Designer" menu.
If you're asking what it does, it's quite simple: SQL will create a new table with the new structure, copy all the data from the old table, drop the old one and rename the new one. If you open the script as described above, you'd see that.

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.