Getting the script of sql server table and stored procedure with out using SQLSMO COM dll from C#

Posted on 2007-08-01
Last Modified: 2013-12-03
Hi All,
            I am looking for way by which i can get the script of an sql server table and stored procedure from C# code with out using SQLDMO.dll which is a COM object.Please help.

Question by:jisha123
    LVL 8

    Assisted Solution

    by:Ashutosh Vyas
    You can create a Stored Procedure that will create scripts for you and call that procedure with the name of the SP.

    Here is a sample of the same

    Author Comment

         Thanks.In this way we get the scripts of Stored Procedure using exec sp_helptext @procedurename, but how can i get the script of a table from code.
    LVL 8

    Accepted Solution

    You can create that manually by obtaining all the columns details of one particular table. You can use something like the below mentioned query to fetch the information of all the columns for a particular table.

    select * from syscolumns where id = (select id from sysobjects where name='your_Table_Name' and xtype = 'U')

    This will output all the columns for that table and you could manually create a string "Create Table................" which will work as a script for you.

    Hope this helps.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now