Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Is it possible to get create/alter/drop scripts from within a SP in SQL server 2005?

Is it possible to get create/alter/drop scripts from within a SP in SQL server 2005?

Scheduled Pinned Locked Moved Database
databasequestionsharepointsql-serversysadmin
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jon_Boy
    wrote on last edited by
    #1

    Just throwing the question out there incase anyone has tried this. When you're using SQL Server Management Studio, you can right click on most objects and manually generate the create/drop/alter scripts. Is it possible to generate the SQL scripts (or send the script text to a parameter) from within a stored procedure? Thanks for any pointers!

    "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

    D 1 Reply Last reply
    0
    • J Jon_Boy

      Just throwing the question out there incase anyone has tried this. When you're using SQL Server Management Studio, you can right click on most objects and manually generate the create/drop/alter scripts. Is it possible to generate the SQL scripts (or send the script text to a parameter) from within a stored procedure? Thanks for any pointers!

      "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      I'm not aware of anything "built in" that would generate the create/alter/drop script for you, but the syntax of these commands is pretty straight forward. For example: IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FSACTIONSET]') AND type in (N'U')) DROP TABLE [dbo].[FSACTIONSET] So you could build your own SPROC to generate the script syntax. What are you trying to do ? Maybe there is a different way to attack your problem. david

      J 2 Replies Last reply
      0
      • D David Mujica

        I'm not aware of anything "built in" that would generate the create/alter/drop script for you, but the syntax of these commands is pretty straight forward. For example: IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FSACTIONSET]') AND type in (N'U')) DROP TABLE [dbo].[FSACTIONSET] So you could build your own SPROC to generate the script syntax. What are you trying to do ? Maybe there is a different way to attack your problem. david

        J Offline
        J Offline
        Jon_Boy
        wrote on last edited by
        #3

        Right, that would be from a drop script. I need to dynamically rebuild a large set of tables. There could be changes to the table on a daily basis, so I was hoping there would be a way to programmatically get at the create scripts and exec it as dynamic sql.

        "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        M 1 Reply Last reply
        0
        • D David Mujica

          I'm not aware of anything "built in" that would generate the create/alter/drop script for you, but the syntax of these commands is pretty straight forward. For example: IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FSACTIONSET]') AND type in (N'U')) DROP TABLE [dbo].[FSACTIONSET] So you could build your own SPROC to generate the script syntax. What are you trying to do ? Maybe there is a different way to attack your problem. david

          J Offline
          J Offline
          Jon_Boy
          wrote on last edited by
          #4

          I think I found a way to accomplish what I need. Thanks anyways.

          "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

          A 1 Reply Last reply
          0
          • J Jon_Boy

            Right, that would be from a drop script. I need to dynamically rebuild a large set of tables. There could be changes to the table on a daily basis, so I was hoping there would be a way to programmatically get at the create scripts and exec it as dynamic sql.

            "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

            M Offline
            M Offline
            Mycroft Holmes
            wrote on last edited by
            #5

            Jon_Boy wrote:

            There could be changes to the table on a daily basis

            This tells me your design sucks. If you are changing table structure daily then there must be something disastrously wrong with your data design. I shudder to consider working in such an environment, it sounds like a nightmare.

            1 Reply Last reply
            0
            • J Jon_Boy

              I think I found a way to accomplish what I need. Thanks anyways.

              "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

              A Offline
              A Offline
              Ashfield
              wrote on last edited by
              #6

              Jon_Boy wrote:

              I think I found a way to accomplish what I need

              Care to share? It might help someone else.

              Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

              J 1 Reply Last reply
              0
              • A Ashfield

                Jon_Boy wrote:

                I think I found a way to accomplish what I need

                Care to share? It might help someone else.

                Bob Ashfield Consultants Ltd Proud to be a 2009 Code Project MVP

                J Offline
                J Offline
                Jon_Boy
                wrote on last edited by
                #7

                Sure Ashfield (thanks for reminding me to do so). I found this thread on another site. It got me pretty close to what I'm trying to do, just modifying to my needs.

                "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups