Reputation: 17
I have created one table 'Temp1'. with fields "id,pName,pid" etc. but i want to Replace this table name with 'temp2' and fields name aslo with "no,name,rollno" without any data loss.
and also add one extra column compName in new created table Temp2.
can any one help me how i can achieve this.
Plz Help me. Thanx in advance.
Upvotes: 0
Views: 29
Reputation: 6017
CREATE TABLE temp2 (no, name, rollno);
INSERT INTO temp2 SELECT id, pname, pid FROM temp1;
I assumed no datatypes or constraints on columns, so you need to adjust if you want some constraints.
Now you can verify that you have all the data in new table. Then, if you no longer need Temp1
, you can drop it:
DROP TABLE temp1;
and if you want to shrink database (remove unused parts of the database file):
VACUUM;
Upvotes: 1