How to add column in middle of table?

I’m not sure, how we can do this in a direct way. But we can do by following way.

Create table test_ram(userID NUMBER
, firstName VARCHAR2(25)
, lastName VARCHAR2(25));

Now we decide to include a middle_name column

Example:
CREATE TABLE temp_ram AS (
SELECT * FROM test_ram);

DROP TABLE test_ram;

CREATE TABLE test_ram (
userID NUMBER
, firstName VARCAHR2(25)
, middlename VARCHAR2(1)
, lastName VARCHAR2(25));

INSERT INTO  test_ram(userID, firstName, lastName)
(SELECT userID
, firstName
, lastName
FROM temp_ram);

DROP TABLE temp_ram;

I’m not saying this is the only way.  This is one of the way to do, if anybody have better solns please post it.

Happy Coding

Ram

Leave a comment