0

Is there a way to generate Table/View scripts and save to a directory using Stored Procedure?

I've a list of all tables/views from different databases that I need to generate but it's in the thousands and doing the task > generate scripts... for each database is very tedious.

I've been looking into Stored Procedures if it is possible to create a script that would create and save all SQL Script using a List but still haven't found any existing samples.

user10888192
  • 27
  • 1
  • 7
  • It's difficult (not impossible) for stored procedures to write to external files. It's easier to use an external tool or script to pull it out... like this https://www.red-gate.com/simple-talk/sql/database-administration/automated-script-generation-with-powershell-and-smo/. Is Stored Procedure an actual requirement or just an idea? – Nick.Mc Sep 16 '19 at 09:46
  • Hi @Nick.McDermaid, I found something similar like this https://stackoverflow.com/questions/706664/generate-sql-create-scripts-for-existing-tables-with-query but when i try it, the alter table is not geting generated. And no it's not limited to SP, if there's anything that could, i'm open for it – user10888192 Sep 16 '19 at 11:42
  • I'm not sure what your purpose is, but you can also use SQL Server Data Tools + Schame compare to generate scripts. You can also generate DDL for every database object from Management Studio – Nick.Mc Sep 17 '19 at 10:19

0 Answers0