0

I just created a database and then added a couple of hundred tables with a script like this:

CREATE TABLE CapBond
(
    [timestamp] varchar(50),
    [Reward] varchar(50),
    [Award] varchar(50),
    [Fact] varchar(50)
)

CREATE TABLE Values
(
    [timestamp] varchar(50),
    [Name] varchar(50),
    [Test] varchar(50),
    [Read] varchar(50),
    [Parameters] varchar(50)
)

I realize I forgot to add two columns to each table. One for the PK and one for an FK that points back to a 'master' table.

Is there an easy way to insert columns without having to drop the DB and recreate it? Preferably with the columns inserted as the first two columns in the table?

1
  • 1
    What database?? Commented Jan 19, 2020 at 0:11

1 Answer 1

1

Yes. In mysql you have the alter table command for this purpose. Check out this page for more detailed explanation https://www.sqlservertutorial.net/sql-server-basics/sql-server-alter-table-add-column/ .

And here is the solution for the ordering of the columns https://www.mysqltutorial.org/mysql-add-column/

Sign up to request clarification or add additional context in comments.

3 Comments

I'm assuming that would be the same for MS SQL? It's been so long since I've done any DB work, I can't remember any commands. I do recall "ALTER TABLE", however, I couldn't begin to remember the syntax. I'll give it a shot. Thanks!
Is it possible to specify the position of the new column?
For the position I am not sure bit the syntax is similar to the mysql one in mssql as well sqlservertutorial.net/sql-server-basics/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.