views:

16

answers:

1

I am relatively new to sql, so I had a question about insertion. I have a table of data that I need to import above the existing content of another table. For example, the table I am bringing in has 100 rows, and the table I'm bringing the data into has 100. I need to make the table I am bringing new data into have 200 rows, and have the first 100 rows blank (so I can update those rows with my new content).

Is there an easy way to do that that I am just missing? Thanks for your help!!

+2  A: 

Consider that the database is just a data store. How it's ordered should be up to the client or the caller. Usually the best means of this is with the ORDER BY clause when SELECTing.

So I'd suggest not worrying about how the RDBMS is storing the data, but how it's being extracted.

Likely there's a column or attribute that you're focused on keeping/maintaining order. Perhaps it's a date or number? Consider using that column in your ORDER BY, and remember you can use more than one column in your ordering.

We shouldn't rely on how the data is stored for presentation later on.

/* use SQLite's current_time to save when these records were created*/
INSERT INTO MyTable (Foo, Bar, CreatedOn)
   SELECT Foo, Bar, current_time
   FROM OtherTable
p.campbell
That's right. Even if you insert records first, there's no guarantee that internally, the database has ordered these first on the hard drive... (that's why indexes need to be rebuilt occasionally.) The order is only determined at the time the data is retrieved.
David Stratton
Thats a great point, I didn't even think of that...thanks!
Steven