Friday , July 19 2024

How To Get Script of Some Objects in the Database On SQL Server(Generate Script Method)


We explained how to get the create script of all objects belonging to the database in the article titled “How To Get Script of the Entire Database On SQL Server (Generate Script Method)“, .

But sometimes this may be giving more than we need.

We only need to get a single procedure or just a single table script.

Right-click on any object on SSMS to get the script for that object.

For example, you can get the script of a view as follows.


You can get table scripts like this.


You can reproduce the examples by yourself.

But I would like to share some details about the tables.

Some tables may have been partitioned.

If you want to get the script of the partitioned table as above, it will not give you the partitioned script .

To access the list of partitioned tables, you can use the script in the article “How To Find Partitioned Tables In The Database On SQL Server“.

After finding the partitioned tables, we can right click on the database and call Tasks-> Generate Scripts as below to get the script of the partitioned tables.


We are proceeding by selecting Do not show this page again on the first screen.


On the next screen, we select the table we want to get the script as follows.

And we call next.


In the screen below we need to specify where to record the Script.

I select the Save to new query window option to open a new query screen and move it there.


If you select Save to Clipboard, you can paste the script with ctrl v.

You can also save it into a file with the sql extension by selecting the Save to file option.

In the next steps, we finish the process by clicking next and finish without selecting another option.


About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *