• Welcome to SQLitening Support Forum.
 

News:

Welcome to the SQLitening support forums!

Main Menu

Copy table to another database with new structure

Started by cj, July 06, 2023, 09:11:53 PM

Previous topic - Next topic

cj

#INCLUDE "sqlitening.inc"

FUNCTION PBMAIN AS LONG

 LOCAL sArray() AS STRING

 slOpen    "old.db","C"  'old schema: firstname,lastname,id
 slExe     "create table if not exists T1(firstname text,lastname text, id integer primary key)"
 slExebind "insert into T1 values(?,?,null)",bindstr("Heidi") + bindstr("Klum")
 slExebind "insert into T1 values(?,?,null)",bindstr("Robert")+ bindstr("Hope")
 slExebind "insert into T1 values(?,?,null)",bindstr("Bugs")  + bindstr("Bunny")
 slClose

 slOpen    "new.db","C"
 slAttach  "old.db","old" 'new schema: id,name
 slExe     "create table if not exists T1(id integer primary key,name text)"
 slExe     "insert or replace into T1(id,name) select id,lastname||', '|| firstname from old.T1"

 slselary  "select firstname,lastname from old.t1 " +_
           "union all " +_
           "select id,name from t1",sArray(),"Q9c"
 MSGBOX    JOIN$(sArray(),$CRLF)

END FUNCTION