insert records into newly added coulumns of existing table.

[expired user #7541]'s profile image [expired user #7541] posted 10 years ago in General Permalink
Hi all,
I want to add new columns and insert some records(withou affecting existing columns) into those coulumns with existing table.. can any one help me out for this.
jfalch's profile image jfalch posted 10 years ago Permalink
add new columns: select table in the tree on the left; click on "Table" tab on the upper right; click on Columns: "Add" button in the middle right.

insert records: select table in the tree on the left; click on "Data" tab on the upper right; in the button panel on top, click "Last" button ( >| ), then click "Insert" button ( + ). Enter first field, press tabe, secosnd field, ...; when finished with fields, press Enter.
[expired user #7541]'s profile image [expired user #7541] posted 10 years ago Permalink
Hi jfalch, thanks for ur reply.. i needed dynamic sql querry. can u please help me out for the required..
jfalch's profile image jfalch posted 10 years ago Permalink
add new columns: cf ALTER TABLE ADD COLUMN ....

modify existing records, set new columns only: generate appropriate UPDATE statements where the SET clause specifies only the new columns. You must have an unique key in the existing records for this to work - eg generate
UPDATE yourtable SET newcol1=value1, newcol2=value2 ... WHERE keyfield=keyvalue
for each existing record.
[expired user #7541]'s profile image [expired user #7541] posted 10 years ago Permalink
if there only few a records then i can use "UPDATE" cluase. But if there are millions of records exists in that table, its not the perfect way to write "UPDATE" cluase for all records.
jfalch's profile image jfalch posted 10 years ago Permalink
AFAIK there is no other way. if you want to change existing records, you have to use UPDATE; the only alternative that I could think of is: you could export the table (using INSERTs), and then modify every INSERT line in the exported file with a program (appending new column values before the ')' at the end of each INSERT clause), then TRUNCATE the table, and load the modified import file.

Please login to leave a reply, or register at first.