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. Alter Tables

Alter Tables

Scheduled Pinned Locked Moved Database
5 Posts 3 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.
  • M Offline
    M Offline
    myNameIsRon
    wrote on last edited by
    #1

    Hi, I'm wondering if it's possible to join ALTER TABLE statements so I don't have to have a bunch of ExecuteNonQuery commands. ALTER TABLE Products ALTER COLUMN ItemNumber TEXT(15) ALTER TABLE ItemsSold ALTER COLUMN ItemNumber TEXT(15) thanks, Ron

    R E 2 Replies Last reply
    0
    • M myNameIsRon

      Hi, I'm wondering if it's possible to join ALTER TABLE statements so I don't have to have a bunch of ExecuteNonQuery commands. ALTER TABLE Products ALTER COLUMN ItemNumber TEXT(15) ALTER TABLE ItemsSold ALTER COLUMN ItemNumber TEXT(15) thanks, Ron

      R Offline
      R Offline
      r stropek
      wrote on last edited by
      #2

      As far as I know this is not possible. Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers

      M 1 Reply Last reply
      0
      • M myNameIsRon

        Hi, I'm wondering if it's possible to join ALTER TABLE statements so I don't have to have a bunch of ExecuteNonQuery commands. ALTER TABLE Products ALTER COLUMN ItemNumber TEXT(15) ALTER TABLE ItemsSold ALTER COLUMN ItemNumber TEXT(15) thanks, Ron

        E Offline
        E Offline
        Eric Dahlvang
        wrote on last edited by
        #3

        You could create this stored procedure, then just execute it with a delimited list of table names:

        CREATE PROCEDURE AlterMyTables
        @cTablesToAlter varchar(500)
        AS

        declare @cSQL varchar(100)
        declare @nLoc int
        declare @nLoc2 int

        select @nLoc = 1

        while (@nLoc<len(@cTablesToAlter))
        begin
        select @nLoc2 = CHARINDEX(',',@cTablesToAlter,@nLoc + 1 )

        if (@nLoc2=0)
          	select @nLoc2 = len(@cTablesToAlter) +1
        
        select @cSQL = 'ALTER TABLE ' + SUBSTRING(@cTablesToAlter,@nLoc,@nLoc2-@nLoc) + ' ALTER COLUMN ItemNumber TEXT'
        exec(@cSQL)
        
        select @nLoc = @nLoc2 +1
        

        end

        ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

        M 1 Reply Last reply
        0
        • E Eric Dahlvang

          You could create this stored procedure, then just execute it with a delimited list of table names:

          CREATE PROCEDURE AlterMyTables
          @cTablesToAlter varchar(500)
          AS

          declare @cSQL varchar(100)
          declare @nLoc int
          declare @nLoc2 int

          select @nLoc = 1

          while (@nLoc<len(@cTablesToAlter))
          begin
          select @nLoc2 = CHARINDEX(',',@cTablesToAlter,@nLoc + 1 )

          if (@nLoc2=0)
            	select @nLoc2 = len(@cTablesToAlter) +1
          
          select @cSQL = 'ALTER TABLE ' + SUBSTRING(@cTablesToAlter,@nLoc,@nLoc2-@nLoc) + ' ALTER COLUMN ItemNumber TEXT'
          exec(@cSQL)
          
          select @nLoc = @nLoc2 +1
          

          end

          ---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters

          M Offline
          M Offline
          myNameIsRon
          wrote on last edited by
          #4

          Thanks Eric, I'll give it a try. Ron

          1 Reply Last reply
          0
          • R r stropek

            As far as I know this is not possible. Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers

            M Offline
            M Offline
            myNameIsRon
            wrote on last edited by
            #5

            Thanks Rainer. Ron

            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