How do you insert all the information from one table to another table using sql command n vb? thanks in advance
Printable View
How do you insert all the information from one table to another table using sql command n vb? thanks in advance
Something like this or like that:This is something I copied from somewhere and adjusted to my program. Big thank you for the original poster!VB Code:
TBN$ = "CodeLinx": Set TB_Any = TB_CodeLinx 'create a temp field 1 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Creation d'un champs temporaire." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..." SQL = "ALTER TABLE " & TBN$ & " ADD COLUMN ActeBackup TEXT(5)" DB.Execute SQL 'take a copy of old data 2 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Copie de l'ancien data." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..." SQL = "UPDATE " & TBN$ & " SET ActeBackup = Code" DB.Execute SQL ' Remove Index 3 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration de l'index." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..." SQL = "DROP INDEX code ON " & TBN$ ' DROP {TABLE table | INDEX index ON table} DB.Execute SQL 'delete original field. 4 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration du champs original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..." SQL = "ALTER TABLE " & TBN$ & " DROP COLUMN code" DB.Execute SQL 'recreate original field. 5 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Création du champs original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..." SQL = "ALTER TABLE " & TBN$ & " ADD COLUMN Code TEXT(5)" DB.Execute SQL 'recreate original Indexes. 6 DB.Execute "CREATE UNIQUE INDEX Code ON " & TBN$ & " (Code)" ' Move back data in original field. 7 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Re-Création du data original." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..." Set TB_Any = DB.OpenRecordset(TBN$, dbOpenTable) 8 TB_Any.MoveFirst While Not TB_Any.EOF TB_Any.Edit TB_Any("Code") = "0" & TB_Any("ActeBackup") TB_Any.Update TB_Any.MoveNext Wend TB_Any.Close 'now we got the data backin, delete the backup field 9 Frm_4to5.Refresh: Frm_4to5.Lbl_Status = "CodeLinx - Epuration du champs temporaire." & vbCrLf & vbCrLf & "Un moment s'il vous plaît..." SQL = "ALTER TABLE " & TBN$ & " DROP COLUMN ActeBackup" DB.Execute SQL
Bert
This will create table 2 and copy all the data from table 1 into it.
SELECT *
INTO TABLE_2
FROM TABLE_1
This will just copy all the data from table 1 into table 2
INSERT INTO TABLE_2 (Field_1, Field_2)
SELECT Field_1, Field_2
FROM TABLE_1
insert into table t1 (select * from t2)
hopefully the structure of t1 and t2 are same