Articles → SQL SERVER → Generate Script For Database Objects Using SSMS

Generate Script For Database Objects Using SSMS






Database Schema




Picture showing the database and the tables inside the database



Steps




  1. Right-click on the database, and go to "Tasks" → "Generate Scripts…"
  2. Picture showing the Generate Scripts... option inside the Task menu


  3. Following window appears on click of "Generate Scripts…"
  4. Picture showing the first screen of Generate and Publish Scripts wizard


  5. Click on "Next" button
  6. Following window will appear
  7. Picture showing the second screen of Generate and Publish Scripts wizard to select the object






  8. Click on the "Next" button.
  9. Following window will appear
  10. Picture showing the options for setting the path of the generated script




  1. Save the generated script as a file
  2. Copy it on the clipboard
  3. Show it in the new query window
  4. Now, click on the "Next" button, and the following window will appear
  5. Picture showing the summary screen of the Generate and Publish Scripts wizard


  6. Click Next and scripts will be generated for the database objects as shown in figure below
  7. Picture showing the last screen of the Generate and Publish Scripts wizard to show the progress of the generated script


  8. Click on Finish to complete the process. A script file will be created on specified path
  9. Picture showing the generated script in the query window of SSMS




Picture showing the popup window of Advanced Scripting options




  1. Script Drop and Create → There are three options
    1. Create → When you want to generate ‘create’ script only for database objects
    2. Drop → When you want to generate ‘drop’ script only for database objects
    3. Drop and Create → When you want to generate ‘drop and create’ script for database objects
  2. Picture showing setting the property of Script Drop and Create attribute


  3. Types of data to script → There are three options
    1. Data only → When you only want to generate scripts for data only. This option is only valid for tables
    2. Schema and Data → When you want to generate scripts for schema of data objects and data of tables
    3. Schema only → When you want to generate scripts for schema only
  4. Picture showing setting the property of Script Check Constraints attribute


  5. Script Indexes → It means while generating the script for tables, you also want to create a script for indexes as well then you can select this option to true
  6. Picture showing setting the property of Script indexes attribute



Posted By  -  Karan Gupta
 
Posted On  -  Friday, April 20, 2018

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250