How to get table script through sql query dynamically.

  • Hi,

    I trying to generate table create script through sql query, for my procedure i'm passing table name and database name as an input parameter it should give the result of the table script and the result of the script should save in any of the local folder of our system (Local path also an input parameter) this is my requirement. Is this possible to get the script and saved to an particular folder.

  • Why do you choose the harder way? You have that in SSMS: right click on a database - > tasks -> generate scripts and then you have the many options - which is essentially important.

    Igor Micev,My blog: www.igormicev.com

  • I wouldn't try doing this through T-SQL. Instead, look to Powershell. There are tons of examples of exactly this type of on demand script generation using PowerShell.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Yes, if you have to go with codes, then PowerShell is the way that offers you easily achieve what you can do with the UI in SSMS.

    Scripting other objects like constraints, indexes, triggers as part of tables could be very hard with t-sql (and you're not sure whether you'd done it well).

    Igor Micev,My blog: www.igormicev.com

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply