Generate a Script in SQL Server 2012
Open you SQL Server and give the login credentials.
Once you login you will can see all the databases In SQL in your object explorer on the right side.
Click on Databases to view all the existing databases in SQL,
From the above databases let us generate a script for KTMBDB database for sample testing.
Right click on database and select-tasks, then
Generate Scripts.
Then it will open a window with the following screenshots,
Based on your requirement, if you want to take complete script you can just click next, else if you want to generate script only for Tables select tables from the above screen. After that click next.
Here I am generating script only for tables by selecting the tables option.
Also you can choose more selective option once you click on Tables .Then click next.
In above screenshot there are some options for us which depends on our requirement.
Firstly, select save to new query window (Best Practise).
Then click on Advance Tab shown above.
Now scroll down the bar and find the following options,
Here, if you want to generate a script only for Schema (Only tables without data then select Schema only else Select Schema with data).
Then click OK and then next.
Nothing to do with this screen, just click Next and then again click next.
Then automatically you will seena script in the SQL Query Window as in the following,
Then change your DB name beside USE at the top of very first line and remove the highlighted area and just run.
Note: Before running make sure you create a new database manually (just simple database).
Please try this when you need and hopefully you will like it.