There are a multitude of reasons why users script existing objects within SQL Server. Depending on the reason will dictate whether you are scripting one object, a few objects, or the entire database. There are different tools within SQL Server Management Studio (SSMS) that will help you create object scripts.
To script a specific SQL object: Right click on the object -> Script [Object Type] As [CREATE To: ALTER To: DROP To: DROP And CREATE To: SELECT To: INSERT To: UPDATE To: DELETE To:] -> Location [New Query Editor Window – File – Clipboard – Agent Job]
Users are able to script an entire database from the Object Explorer. This option scripts out only the database configuration options and not specific objects within the database.
Right click the selected Database -> Script Database As -> [CREATE To: DROP To: DROP And CREATE To:] -> [New Query Editor Window File Clipboard Agent Job]
Generate Scripts Wizard
This option provides the most options for selecting what is scripted and what is included.
Right click database -> Tasks -> Generate Scripts
This will open the Generate and Publish Scripts wizard. You can select to script the entire database or specific object(s) within the database (Tables, Views, Stored Procedures, User-Defined Functions, User-defined Data Types, DDL Triggers, Xml Schema Collections, Schemas, Full Text Catalog).
Once you have selected everything to be scripted, click Next. This will take you to the Set Scripting Options page. Select the Output type and where the script will be saved.
Click on the Advanced button to modify any of the advanced scripting options. When you are done making changes to the scripting options, click on the Close button.
Click Next to review your scripting selections.
Click Next to save/publish scripts.
Click Finish to close the Wizard.