Dennis Cote wrote:
> 
> Carradine wrote:
>> Hello, I am attempting to simply copy a table with data from one database
>> to
>> abother database with the command:
>>
>> attach database 'DB.db3' AS V1
>>
>> CREATE TABLE Table1 AS SELECT * FROM V1.Table1
>>
>> The creation of the table, and the copying of the data works great. 
>> However, my ID field from the original database is an INTEGER PRIMARY
>> KEY,
>> but when the table gets copied over, it only becomes an INTEGER.
>>
>> Am I defining my SQL statements wrong?  Or am I going to have to use a
>> CREATE INDEX call when coying over my table?
>>
>>
>>   
> Carradine,
> 
> The types of the columns in a CREATE ... AS SELECT ... statement are 
> inferred from the result of the SELECT. You will need to create your new 
> table using the same  create statement used in the V1 database (i.e. the 
> one with the INTEGER PRIMARY KEY), and then do an INSERT ... SELECT .... 
> instead.
> 
>     create table table1 as (....);
> 
>     attach database 'DB.db3' as V1;
> 
>     begin;
>     insert into table1 select * from V1.table1;
>     commit;
> 
> HTH
> Dennis Cote
> 
> 

-----
Thanks, that worked.  I wanted to get around doing the extra step of
re-defining the table, but I can live with it for now.
 

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------



-- 
View this message in context: 
http://www.nabble.com/Primay-key-trait-is-lost-when-copying-across-tables-tf2397051.html#a6684691
Sent from the SQLite mailing list archive at Nabble.com.


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to