开发者

How to insert X amount of rows at the beginning of a pre-existing table of data in sqlite

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 h开发者_StackOverflowelp!!


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜