insert

cnsg
04-20-2004, 08:30 PM
at the beginning,i have a table with one single column header "a" and 5 records.and then i add a new column "b" using ALTER TABLE.now i want to insert value to column "b",so i use conn.execute "insert tablename (b) values (123)" and this is a repeat loop because i want to insert value to all the 5 records. the problem is, the table has 10 records in the end, the top 5 have values (NULL,123),(NULL,xxx) and so on while the left 5 have values (XXX,Null),(xxx,Null)...why it is so ? how to write the code then ? thanks!

N.B. value (NULL,123) is in form(column a,column b) and xxx are real values

MKoslof
04-20-2004, 08:33 PM
If you do an INSERT statement, you are ADDING five NEW records to the existing table. So, if you had 5 records initially, now you will have 10. After you run your alter table..there are now two fields...but you also already have five records. Instead of doing an INSERT statement, if you want to MODIFY the existing five records (by adding a value into the newly created field) you should do an UPDATE statement.

cnsg
04-20-2004, 08:47 PM
thank you very much !
can you tell me how to update the column ? i use "update tablename set b=1" all the column have value 1,so how to update field one by one?

Kashif
04-21-2004, 01:54 AM
thank you very much !
can you tell me how to update the column ? i use "update tablename set b=1" all the column have value 1,so how to update field one by one?

Use Where clause in the Update Query.

cnsg
04-21-2004, 03:13 AM
Use Where clause in the Update Query.
thanks! done!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum