In SQL Server 2012 you can generate a script of your database as in the following:
- Open SQL Server. Expand databases by right-clicking on your desired database then click on Tasks and then click on Generate Scripts.
- Now you have the following two options:
1) Script the entire database (get a script of the entire database)
2) Select specific database objects (get a script of specific objects or tables)
Select your choice and click on "Next".
- Here specify the name and location for the script.
- And select the option of Script For Server Version (for which version of SQL Server you are generating the script) as in the following:
- Types of Data to Script Option: if you want to generate a script of only the Schema (empty database) then select the option of “Schema Only” and if you want to generate a script of the schema and the data (database plus data) then select the option of “Schema and Data”.
- Then click on OK and then a dialogue will appear where you can find the status of the script and after a successful generation of the script click on "Finish".
- If you want to run this script on another system then just double-click on the script and it will be opened in SQL Server then click on execute and the database will be attached successfully.
Thanks. Looking for your positive responses.