473,698 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Generating rows for insertion

geon
1 New Member
Hi!

I have a table I'm using as a stack to pop rows from. (The data in the stack is precomputed for efficiency and reliability.) There are a lot of duplicate rows in this table (hundreds or thousands of identical rows), but they are all inserted with a regular insert statement.


I have optimized it by using the multiple row insert syntax:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName (Col1, Col2) VALUES
  2. ("Some value", "Another value"),
  3. ("Some value", "Another value"),
  4. ("Some value", "Another value"),
  5. ("Some value", "Another value"),
  6.  
That helps a lot, but it's still terribly slow. (Nothe that there might be hundreds of identical rows inserted like this.)

I was thinking of mowing all this to the server insted, like this:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName SELECT "Some Value" AS Col1, "Another value" AS Col2
But I would need some way of reliably generating n rows from the select statement. I saw an example doing it this way:

Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName SELECT "Some Value" AS Col1, "Another value" AS Col2 FROM AnotherTableName LIMIT n
Where "n" would be the number of rows to insert. But what if there are no rows in the second table?

Any ideas?

(This is all going to be running on a webserver I do not have control over. Probably a FreeBSD/Linux solution with Apache/MySQL/PHP.)
Oct 12 '07 #1
1 1603
mwasif
802 Recognized Expert Contributor
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName SELECT "Some Value" AS Col1, "Another value" AS Col2 FROM AnotherTableName LIMIT n
Where "n" would be the number of rows to insert. But what if there are no rows in the second table?
'n' is the number of rows to SELECT. If there are no rows, it is not going to INSERT anything.

You can use this statment to INSERT the data in pieces e.g. INSERT first 100 rows
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName SELECT "Some Value" AS Col1, "Another value" AS Col2 FROM AnotherTableName LIMIT 0,1000
Then next 1000
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName SELECT "Some Value" AS Col1, "Another value" AS Col2 FROM AnotherTableName LIMIT 1000,2000
Nov 6 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

13
3786
by: J. Campbell | last post by:
I'm wanting to output a text header file in front of the data portion of an output file. However when I use "\n" or "endl" as end of line, it just puts a 0x0a in the file(which is non-printing)...in Windows you need the (0x0d 0x0a) pair, if you want a new-line in a text editor. What's the correct way to get this 2-byte sequence into a file? Thanks #include <iostream>
0
1318
by: Murad Nayal | last post by:
Hello, I vaguely remember reading in the manual that the order of the retrieved rows in a response to a select statement is unpredictable (unless you use an order by clause). this possibly depends on the indices set up for the table and/or used in constructing the result etc. is this accurate? if so is there any way to insure that rows retrieved are returning in the order by were inserted in, say other than ordering by some 'insertion...
4
3998
by: Mark | last post by:
BEGINNER QUESTION I have a table which has a compound primary key consisting of two columns. One of these columns is a foreign key which is generated in another table by an identity. I want to be able to generate the other primary key column value automatically when an insert occurs but assume that I cannot use an identity because it would have to be unique for this table.
4
1127
by: s99999999s2003 | last post by:
hi i wish to generate a table using cgi toprint = print '''<table border="1"> <tr> <td>User</td> <td>Name</td> <td>Address</td> </tr> <tr>
9
5002
by: YONETANI Tomokazu | last post by:
Hi. You can use the following SQL to construct rows with column names on the fly, rather than from an existing table like sysibm.sysdummy1: SELECT * FROM TABLE ( VALUES (0, 1, 2), (3, 4, 5), (6, 7, 8) ) X(foo, bar, baz); or WITH X(foo, bar, baz) AS ( VALUES (0, 1, 2), (3, 4, 5), (6, 7, 8) ) SELECT * FROM X;
5
1970
by: Henry | last post by:
Dear all, Is there any DB2 SQL statement that could generate rows of intermediate dates by providing the start and end dates?? If 2006-1-1 and 2006-1-31 are provided to the SQL, the output will look like : 2006-1-1 2006-1-2
7
3674
by: tatata9999 | last post by:
Hi, SQL env: sql server 2000 Target column of insertion: varchar(15) Case, a var is made up of a character of the following characters (random selection): A,B,C,D,E,$,!,%,^,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,&,*,(,) and a few numbers (random selection), and then
7
4720
by: Don Li | last post by:
Hi, Env is ms sql server 2000. ddl: create table srchPool(tid int primary key, taid int, s tynyint, uid tynyint); -- and sql server automatically creates a clustered index for the pk dml:
10
18406
sumittyagi
by: sumittyagi | last post by:
Hi All, Is it possible in oracle to insert multiple rows in a single insert query, as is possible in sql server: insert into test_table values ('abc', 'xyz'), ('mno', 'pqr'); This syntax is not supported in oracle. Is oracle having any alternative for this one. Thanks & happy new year in advance.
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8603
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9023
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7721
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.