Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    MYSQL




Consecutive Ids In A Batch Insert


I am new to mysql and would appreciate any advice that you have to
offer.
I am attempting to batch insert 100 rows into a table, and I need to
know the 100 id's of all the inserted rows.

I know that I can find the id of the last inserted row despite my app
being multi-threaded, since the select last inserted command is
connection-specific.

Given the id of the last inserted row, can I back out all the ids of
the inserted rows? Are the inserts consecutive in an auto-increment
table?

If not, I will be looking to lock the table during inserts, but that
seems very sub-optimal.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Consecutive Ids In A Batch Insert?
I am attempting to batch insert 100 rows into a table, and I need to know the 100 id's of all the inserted rows.

I know that I can find the id of the last inserted row despite my app
being multi-threaded, since the select last inserted command is
connection-specific.

Given the id of the last inserted row, can I back out all the ids of
the inserted rows? Are the inserts consecutive in an auto-increment
table?

If not, I will be looking to lock the table during inserts, but that
seems very sub-optimal.

Running mysql 5.0.24

Auto_increment Consecutive
After a multiple-row INSERT statement, LAST_INSERT_ID() returns the id of the first row inserted. But is it always guaranteed that the subsequent rows will all be consecutive from there, in the order in which they were specified in the INSERT statement, even if two processes are trying to insert things at the same time? Or might it leave gaps or shuffle them? In other words, is it safe to deduce the id's of all the rows I've just inserted from the id of the first one? I couldn't find any documentation which told me one way or the other.
Thanks for any help. I'm using MySQL 5.0 with an InnoDB table but it would be interesting to know for other table types too.

Adding Two Consecutive Rows
I have a table with the following fields

id | time | usuage
6 13:0010
613:3015
6 14:007
614:303


How do i add rows with time 13:00+ 13.30 so that the total usage for 13:0 become 25
similarly for 13.30 the total usage become 22

id | time | usuage | Total usage
6 13:001025
613:301522
6 14:00710
614:303(3+usage of 15.00)

Executing Consecutive Multiple Statements
I'd like to execute 4 INSERT statements as a single query to the database, constructing a single string (in php), and executing a mysql_query with sql like this...

INSERT INTO users VALUES(NULL, 'steve', ...);
INSERT INTO users_groups VALUES((SELECT LAST_INSERT_ID()), 1);
INSERT INTO users_groups VALUES((SELECT LAST_INSERT_ID()), 2);
INSERT INTO users_groups VALUES((SELECT LAST_INSERT_ID()), 3);

In the final 3 statements (inserts into users_groups), the first field value must be the auto-increment value of the first insert statement (insert into users).

However, the users_groups table also uses an auto_increment value, and so will the final two calls to LAST_INSERT_ID() return the id of the last insert to the users_groups table? I can see this could be a problem.

If so, is there anyway to achieve what i'm trying to do without resorting to multiple queries? Something like setting a variable with the value of LAST_INSERT_ID() and then using that variable in the subsequent inserts?

Consecutive Rows In An Auto-increment Table
I was curious if anyone had some insight to this puzzle:

There is an 2 column auto-incrementing table such as 1 -> data1, 2 -> data2, 3 -> data3, and so on, where the numeric index increments at each new INSERT of data. Sometimes, I'd manually modify the table and erase entries for editing purposes. Let's say the latest entry was 3 -> data3 and i erase it, then the next INSERT goes to 4 -> data4 so the table is now 1 -> data1, 2 -> data2, 4 -> data4. The 3rd index can never come back unless manually insertted.

Now my question is, on a larger scale, how can I SELECT out a series of consecutive rows?

Let's say there are 100 rows with "numeric loop holes" of auto-incrementing index similar to the example i gave. I want the next ten rows (increasing index) after the 10th index. Of course, I can't just loop from 10 to 20 via table's index since some indexes may have been erased manually. Any methods to do this?

Batch Mode
I understand that to use batch mode it is necessary to put the commands you want to run into a file before telling MySQL to read its input from the file, but how do I create the file and what do I create it in? Also, I'm not really sure how you would then tell MySQL to read it.

Using Batch Files
I have a small problem with using batch files (platform: Windows XP). The problem I have is that I do not want to place and call all my db batch files from within BIN folder, but rather from, say c:a1a2a3. Calling a batch file in Windows like this is not an issue:

mysql>source c:/a1/a2/a3/test.sql;

Then, you can call test.sql from test2.sql, for example, by the same line of code:

source c:/a1/a2/a3/test.sql;

Is there any way to keep the base direcory, i.e. c:a1a2a3 in some sort of environment or whatever variable and then use it in the parameter passed to the source command.

I have experimented with user-defined variables to no avail:

SET @BASEDIR = 'c:/a1/a2/a3/test.sql';
SOURCE @BASEDIR;

Batch Mode
I want to execute the queries wriiten in a .sql file in a single attempt using the batch process of mysql.Since I don't have a good grip over the database systems, I am confused how should I go for it..

Using Batch Mode
can someone show me the way of using batch mode?
what is the syntax of it?
what should i do for the first step?
can someone tell me about that?

Batch File
I am new to running batch files. Is there a way to loop through a results set in a batch file? I want to be able to create tables using table names that are stored in a table. I had hoped that I could query the table to retrieve all tablenames, then loop through this result set, creating a table with each tablename returned. (Table definitions will be the same for all tables created. Only the tablenames are different.)

Cant Execute Batch File
Hi new to this but pulled out nearly all my hair with this.
I got the test database open and I want to automate creating the menagerie table ( as in the tutorial ) so I download the textfile save it to c:/ and execute the command source c:/cr_pets_tbl.txt all I get is unable to open file error 22.
I have tried creating my own text file ( windows, notepad ) just containing the following
use test;
create table pets(name varchar(10),species varchar(8),born date);

simple as that then type in the consoe source c:/pets.txt;
unable to open file error 22 or sometimes error 2
tried enclosing filename in " and ' tried source= filename
tried . instead of source but nothing works.
using manual insert command or load data local infile works but not this, HELP.
Malcolm K.

Batch File For Backup
Can I make complete Backup of a database (same as from MySQL Administrator) using batch file?

Getting Error In Batch Update
I am using Mysql 4.1.13 with Tomcat5 and Connector mysql-connector-java-3.1.10. When I try to update the table in batch mode sometimes( When server is idle for a long time) get following error. Code:

Batch Mode Problem
I am having a problem with 2 sql statements in 1 batch file. Only the last
statement executes. If I separate the statements into individual files they
work fine.

Are you only allowed 1 statement per file?

Here is the contents of the batch file:
insert into monlog (monlog_locno, monlog_custno, monlog_time,
monlog_inputdate, monlog_errno) select loc_no, loc_custno,
(hour(now())*60)+minute(now()), now(), 200 from loc where
loc_next+29<(hour(now())*60)+minute(now())+30 and loc_errno>=200 and
loc_errno<=249;
update loc set loc_errno='250' where
loc_next+29<(hour(now())*60)+minute(now())+30;

Mysql Batch Question
I'm writing this here because it's related to mysql. I'm using Mysql with PHP and because Mysql 4 doesn't support stored procedures, I would like to run several scripts from one database connection. In running a multi-line sql.txt file externally I can do this by delimiting the statements with a semi-colon so I tried to do the same:

$strsql = "";

$strsql = "delete from tbl1 where tbl1ID = '1';";
$strsql = $strsql . "delete from tbl1 where tbl1ID = '2';";
$strsql = $strsql . "delete from tbl1 where tbl1ID = '3';";

$result = @mysql_query($strsql, $db);

I'm not getting an error; the sql scripts simply won't run.

Batch FIle To Create Database
I am trying to create a batch file to create a database and populate it with create table statements. I can't figure out why it will not create the database and load the tables. I have the following in my batch file

/mysql/bin/mysql.exe -vvv -u root -pcs3911 < C:mySql est.txt

and the following is my test.txt file

CREATE DATABASE 'lovettsite';

CREATE TABLE `applications` (
`username` varchar(255) NOT NULL default '',
`firstname` varchar(255) NOT NULL default '',
`middlename` varchar(255) NOT NULL default '',
`lastname` varchar(255) NOT NULL default '',
`current_address_line_1` varchar(255) NOT NULL default '',
`current_address_line_2` varchar(255) NOT NULL default '',
`current_city_town` varchar(255) NOT NULL default '',
`current_state_province` varchar(255) NOT NULL default '',
`current_zip_code` varchar(16) NOT NULL default '',
`p.........................................................................


Running MySQL Using A Dos Batch File
I am used to use MySQL on Unix, now I have to do some development for MySQL running on Windows machine. The following script works well in Unix but I am unable to run it on Windows. "MY_FLAG" is the one which is causing issue. Due to certain restriction in my framework, I can use the normal batch by supplying the .sql file while opening the mysql connection ( infact i need to run multiple source files) Code:

Prepared Statements (for Batch Inserts)
I am looking into using prepared statements as a possible performance optimisation in my application. I am currently using a batch insert statement:

insert into mytable values (d11, d12, d13), (d21, d22, d23),...,(dn1, dn2, dn3)

The database insert/select logic is multi-threaded. The number of rows that are to be inserted in the batch is variable. I am using Connector/NET to access MySQL from the application.

MySqlCommand as far as I can tell is not thread safe which means creating a new command instance for each statement the application needs to execute for each thread.

How does this affect prepared statements ? Are they automatically cached under the hood so if a new MySqlCommand is created using a previosuly prepared statement, is this handled so as to prevent "preparing" the statement again ? Do I need to cache each MySqlCommand instance for each unique prepared statement ?

What performance gains if any will I get if I use prepared statements instead of non-prepared statements for batch inserts as shown above?

How would I define the prepared statement parameters for a batch insert with a variable number of rows ?

See Feedback Message On Batch Mode
I wrote a perl program to update/insert mysql
database. It worked fine but I could not see the feedback message to
show how many rows updated or inserted. I can see that if I issue SQL
commands interactively.

BTW, what's the easiest way to check return code from SQL commands in
perl. I use korn shell script to invoke perl script that does SQL
stuff. I need to pass the return code back to shell script.

See Feedback Message On Batch Mode
I am new on mysql. I wrote a perl program to update/insert mysql
database. It worked fine but I could not see the feedback message to
show how many rows updated or inserted. I can see that if I issue SQL
commands interactively.

BTW, what's the easiest way to check return code from SQL commands in
perl. I use korn shell script to invoke perl script that does SQL
stuff. I need to pass the return code back to shell script.

Using Batch-/cmd-file For Dumping Data
i want to build in data in my database that are written in single table dumps like [tablename].sql.

Each time it is nececery to use several files. And it is also nececary to do this using the command line because of the files are bigger than 1,5 gb
But i didnt find a way to transfere the needed commands into the mysql command line.

How To Execute A Batch Sql File Under Windows?
I have installed MySQL 5 in c:Program FilesMysql. I have a sql file named "books.sql" which is put in the subfolder in,it contains many statements that like "INSERT ... value ...".

my question is how to execute it? I try it, but failed.

One more question is how can I return from "->" to "sql>" promopt?

Tabs Missing In Batch Mode
in a shell script of mine I'm executing a mysql SELECT in batch mode. I
want to use the return value for other sql statements.
The problem I'm facing is that the tabs, which seperate the columns
from each other, are missing in the output.
What am I doing wrong?

#!/bin/sh
QUERY="select id, i.handle from idmap i, person p where
i.handle=p.handle and email="$1""
mysql mydatabase -pmypassword -N -B -e "$QUERY" | while read line ; do
personid=$(echo $line | cut -f1) ; handle=$(echo $line | cut -f2 ) ;
echo $handle ; done ;

Running A Sql Batch Script From The Linux Command
s this possible?

I want to write a command script which i want to put into a cron job which will download a db backup from cpanel. then i want to unzip it, and run the sql file, so keeping the database on the mirror machine up to date.

So what i have is:

#get the database
wget -v --http-user user --http-pass pass https://www.site.com/path/to/cpanel/backup
#move to backups folder
date=`date -I`
mv -fv ./mysqldump.gz /home/user/dbbackup/$date.gz
now what i also want to do is:

mysql -uuser -ppassword
u database
set foreign_key_checks = 0;
. mysqldumpfile.sql
set foreign_key_checks =1;
exit
is it possible to do that last bit from the command-line? as far as i know, a shell script can't run commands to mysql?

Batch Query Or Large List Of IN() Arguments?
I'm receiving a potentially large list of productID numbers from an external data source.

Each productID has a number of partID's associated with it and those partID's are stored in my database.

I would like to create a list of products sorted by the number of parts each has.

If I only have one table called "part" which stores a partID and its associated productID, which of the following methods would be more efficient assuming the application and DB are on the same server.

Option A)

SELECT productID, Count(*) counter
FROM part
WHERE productID
IN(large list of productID's received, maybe 1 or >10000)
GROUP BY productID
ORDER BY counter DESC
LIMIT ?, 10

Option B)

Execute a batch query of prepared statements (SELECT COUNT(*) FROM part WHERE productID=?) for each product in the received product list then sort the returned results in the Java app that is making the query.

Option C)

???

Running Mysql Commands In A Batch File
I am trying to automate a mysql command to upload data everymorning on a windows server. I have created a .bat file and entered the commands to login to mysql but when it gets to the mysql prompt it fails to complete the rest of the commands.

cd
c:
cdmysqlin
mysql
TRUNCATE TABLE blah
LOAD DATA INFILE 'blah.txt' INTO blah
QUIT
exit

Is this possible?

Mysqld-nt Crashes When Executing Batch File In 5.03 Beta
I'm quite new to mysql but I had installed the 5.0.1 and 5.0.0a alpha under windows XP, and designed a little database for managing cards. To make some backup of this database I dumped it in a batch file. This file was working perfectly with mysql 5.0.1 and 5.0.0a.

When I try and execute my batch file, having previously created the database concerned, it crashes the mysqld-nt. On top of that the first table created in the database is listed but when a DROP DATABASE is issued it says that this table does not exist and then the command fails.

The database uses UTF8 and SET FOREIGN_KEY_CHECKS=0; is set in the begining of the file.

So I have two questions :

1- Can I force the database to be dropped or is it definitely corrupted?

2- Any clue on why the batch file crashes the server? (I'd be glad to send it is is a mere 250 ko when zipped)

Batch Mode Feedback Of &quot;mysql&quot; Command Line Tool
while writing a bash shell script to backup some databases and I am having slight problems with the mysql command line tool's feedback.

Here goes command line:

#!/usr/bin/env bash
mysql -ubackup -e "UPDATE `mydb`.`sysvar` SET `val`='backup' WHERE `var`='updateState' AND `val`='0';"

The backspaces are nescessary for the shell, otherwise it'd interpret whatever is inclosed in --> ` <--- as command.

The problem is, I need to know wether a line has changed or not. The command always returns 0 (that is a success in Unix/Linux) if it was successfully executed, no matter wether or not a line had been changed, and produces no output at all.

Could anyone tell me how I get that info?

Insert Multiple Rows With One Insert Stmt And Nested Select
I'm trying to insert several rows into a table using only one insert statement:

insert into component_feature values (select 3,1,sf.software_feature_id,1 from software_feature sf where sf.software_id = 1)

When I run the select statement alone, I get the result I want:

+---+---+---------------------+---+
| 3 | 1 | software_feature_id | 1 |
+---+---+---------------------+---+
| 3 | 1 | 0 | 1 |
| 3 | 1 | 1 | 1 |
| 3 | 1 | 2 | 1 |
+---+---+---------------------+---+

But when I run the complete statement I get:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'select 3,1,sf.software_feature_id,1 from software_feature sf where sf.software_i' at line 1

This query is part of a PHP application I'm building. I'd rather not have to write a PHP loop to do multiple inserts.

How To Insert Multiple Rows With 1 Insert Query
I am having a form on the front end which has for example 3 rows each with 3 columns. The user enters data in all the 3 rows. When he hits the add button these should get in the database. What insert query would I write to add all of them together to the database? Do I need to use some procedure?

Insert Using MAX()+1
I have a table like this:

id pnt name val
0 1 x 3
1 1 y 5
2 1 z 2
3 2 x 4
4 2 y 3
5 2 z 6
6 3 x 2
7 3 y 2
8 3 z 3

What I want to do is make an insert that looks for the highest value of "pnt" (for this example: 3), adds 1 (now 4) and inserts the next set of X,Y,Z values to that "pnt"...

I tried this:

INSERT [INTO]
i'm curious about the meaning of 'INTO'. in the mysql-docu, it is declared as an optional keyword

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE]
[INTO] tbl_name [(col_name,...)]
VALUES ({expr | DEFAULT},...),(...),...
[ ON DUPLICATE KEY UPDATE col_name=expr, ... ]

but each of the following examples is 'INSERT INTO', there ist no 'INSERT' without 'INTO'.

So what is the a difference between 'INSERT' and 'INSERT INTO',

INSERT INTO
I am in need of some help. We have a database that has two tables, one that holds a computers information and the other that holds model numbers that computers have.

The tables are set up like this:

tbl_comp: comp_ID (auto), comp_mod_ID (num), comp_desc (Char)

tbl_model: mod_ID (auto), mod_modelName (Char)

I can perform an INSERT command to enter a computer, but in order for it to reference the Model Number table, I have to use the mod_ID field. (which I think is best practice)

I want to be able to do the INSERT command, but use the modelName instead. So I think I need to do some kind of lookup, where I pass in the modelName, but it inserts in the modelID.

However, I do not know what to call this procedure, and therefore I cannot search for help on google.



LAST INSERT ID
When i use SELECT LAST_INSERT_ID(cd_Code) AS next FROM tb_Client
(note - cd_Code is autoincrement)

it shows all the records from cd_Code if i do LIMIT 1
it shows me the first one

how can i do for it to show me the last maximum record?
how can i do for it to show me the last record i inserted?

Cannot Insert
i just don't understand why i cannot insert some form data into MySQL INNODB table:

insert statement$q = "INSERT INTO books VALUES ('$title', '$author')";
return mysql_query($q, $this->connection);
first tableCREATE TABLE books (
title varchar(90),
author varchar(90)
) TYPE=INNODB;

no problem at all insert form data into this table, but when i change the table to CREATE TABLE books (
book_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
title varchar(90),
author varchar(90)
) TYPE=INNODB;

i cant insert nothing, very strange! there's no foreign key involved, just a single table. what's the problem?

Last Insert Id
drop table t1;

create table t1 (id smallint not null auto_increment, name varchar(20), primary key(id)) engine=innodb;

insert into t1(name) values ('a');
insert into t1(name) values ('a');
SELECT * FROM t1 t;
select LAST_INSERT_ID();
-------------------------------------

The records are added correctly in the table, but last_insert_id always returns 0.

Using USE &amp; INSERT
I am trying to help someone install an addon to an existing script. The addon uses one database and the existing script uses another. The purpose of the addon is to allow the 2 databases to share login information so new users don't need to login separately.

Anyhow I have installed this successfully on my site and another site. This person I am helping has a database name that I believe is causing the issue and I am not sure how to help this person work around this, as it appears their host/server is creating the part of the database name causing the trouble.

So I need to know how to instruct them to run the "sql" query successfully.

The code is shown below, the issue appears to be with the use of the "-" character in the databae name. I tried to create this "-" in the database name on my test site and the server eliminates the "-" and created the database without it, so I couldn't test it.

Code:

How To Always Insert In To Last Row
I am making my first PHP/mysql script and I have run in to a problem. Say I have a table with a unique ID that auto increments:

ID ,NAME, DATE
1 , EXAMPLE1, DATE1
2 ,EXAMPLE2, DATE2
3 ,EXAMPLE3, DATE3

So every time I add a new record, its inserted and the ID autoincremented. That part is working fine.

The problem I´ve run in to is when I tried to delete a record, say record ID #2,
it´s deleted. But when I try to insert a new record, it´s inserted where the deleted ID used to be.

So in my example,after I delete record #2 and I want to insert new record #4 this is what I get:

ID ,NAME, DATE
1 ,EXAMPLE1, DATE1
4 ,EXAMPLE4, DATE4
3 ,EXAMPLE3, DATE3

Notice that it gets the ID# correct, but I actually want it to go after ID#3,like so:

ID ,NAME, DATE
1 ,EXAMPLE1, DATE1
3 ,EXAMPLE3, DATE3
4 ,EXAMPLE4, DATE4

Since I am a MySQL newbie I´m pretty sure there must be some sort of setting when I create the table that will make this work the way I want it to, but after lots of reading and searching I havent been able to find it.

Not Getting Last Insert Id
I am using a custom php class where i have wrapped all the mysql
connection settings and query functions. Instead of calling direct
mysql functions i creat an instance of this class and than use the
custon functions for query, connection etc. At some places i also use
direct php mysql functions to connect and query.

My problem is that on my web site sometime i dont get last insert id of
an insert query. Is it because connections are shared or is there some
other problem. If i force mysql to always open a new connection for
query will it overload my server.

Insert New Row Only If There Is No Such Row...
e.g. I have table t (c, a, b);

I want to insert information in the table only if a and b are not present.

I used to write :
if not exists (select c from t where a="from" and b="from")
insert into t(a,b) values("from", "from");

as I always get an error, I read that there is 'not exists', and 'if' functions, but...

how can I rewrite this query into a good query( I must use joins and etc.? :( )?

or should I make unique composite index on a,b columns? :) and ignore errors when inserting?

Insert Row
Insert row beteewn to old rows. I have a database and I need a certain
order of the rows, and would like to insert a row between tod old rows.
Can that be done?

I use phpmyadmin and i belive i once saw such a feature, but I can't
find it now.

Insert A Value
how to write my sql so I can insert a value that is in the $GLOBALS array.
Here is my code which does not have syntax errorss (when I don't refer to $GLOBALS but I also don't get the value !!!)
$query = "INSERT INTO `T_Car` (`T_Car_NewPrice`) VALUES ('$Db_Car_NewPrice')";

here is the code which I would like to have (since the variable value is in $GLOBALS)

$query = "INSERT INTO `T_Car` (`T_Car_NewPrice`)
VALUES ('$GLOBALS['Db_Car_NewPrice']')";

I tried different alternatives of this previous syntax (ie surrounded by {} or ' ' but without success.

Insert One Value After Another Value
give me the syntax to insert a new row of data in a particular place in a table? I think it is something close to:
INSERT INTO Table VALUES ("X") AFTER ?

I am trying to add a record to an alphabetized list. I don't want to query the list to alphabetize it, but actually have the data alphabetized.

INSERT INTO W/$var
I'm building a script installer that must prepopulate a MySQL table according to vars set in the config file:

// Configure the following variables
$primary_email = "agreements@yoursite.com"; // System email address
$admin_email = "admin@yoursite.com"; // Administrator's email
$extra_email = "additional@anothersite.com"; // Additional email

$db = @mysql_connect("$host", "$dblogin", "$dbpass");

$sql= "INSERT INTO ".$tablepre."admin (id, level, e_robot, e_add1, e_add2, thanks_url)
VALUES (1, 1, ".$primary_email.", ".$admin_email.", ".$extra_email.", 'thanks1.php')";
$result = @mysql_query("$sql",$db);
No parse error but nothing gets inserted. What am I missing here? It works fine without the vars (naturally).

Last Insert ID
Scene
ID: Long, auto incremental, index
Content: VarChar(1000)
CreateOn: Date
TestID: VarChar(12)

TestID is of the format "T-YYYY-ID", ie: T-2008-00001, where 00001 corresponds to the ID which I have just inserted.
Any idea how to do it?
Ideally, in ASP.NET, the command would be
insert into Scene (Content, CreateOn, TestID) Values
("testContent", DateTime.Now, "T-"+DateTime.Now.Year.ToString()+"-"+Mysql_last_ID()); ??? or
insert into Scene (Content, CreateOn, TestID) Values
("testContent", DateTime.Now, "T-"+DateTime.Now.Year.ToString()+"-"+Max_ID+1);

I have managed to do it, but was wondering if I can improve it by using a subselect? Currently using ASP.NET with MySql.Data.MySqlClient

MySqlConnection conn = new MySqlConnection(connectionString);
MySqlCommand command = new MySqlCommand("Insert_Scenario", conn);
command.Parameters.Add("?content", MySqlDbType.VarChar, 1000);
command.Parameters.Add("?createOn", MySqlDbType.Date);
command.Parameters.Add("?testID", MySqlDbType.VarChar, 15);
command.Parameters[0] = "testcontent";
command.Parameters[1] = DateTime.Now;
command.Parameters[2] = " "; //insert empty first
command.CommandType = CommandType.StoredProcedure;
command.ExecuteNonQuery();

// Get latest ID
string strSQLSelect = "SELECT @@IDENTITY AS 'LastID'";
MySqlCommand dbcSelect = new MySqlCommand(strSQLSelect, conn);
MySqlDataReader dbrSelect = dbcSelect.ExecuteReader();
dbrSelect.Read();
long intCounter = long.Parse(dbrSelect.GetValue(0).ToString());
dbrSelect.Close();

// Format new command string
string tno = "T-" + DateTime.Now.Year.ToString() + "-" + intCounter.ToString().PadLeft(5, '0');
string sqlCommand = "Update Scene set TestID='" + tno + "' where ID=" + intCounter.ToString() + ";";

// Update the column
MySqlCommand command1 = new MySqlCommand(sqlCommand, conn);

command1.CommandType = CommandType.Text;
command1.ExecuteNonQuery();

conn.Close();

Help On Insert
i m trying to insert a new records into a table,
my query is

INSERT INTO test
SET rank = ( SELECT max( rank ) + 1
FROM test )

i have a error returned (#1064)

may someone help me to find the correct syntax?

INSERT
I have an existing table that has already a few fields that are filled with data. This table contains also a few empty fields. I want these empty fields to be filled with data while specifying the row where this data has to be putted.
Appearently INSERT and WHERE can't be a combination.

Insert
insert into table values(whatever)

How can i tell sql to only insert into the table if a value doesnt yet exist?

i.e. Dont insert if its already there.

Insert
Is there a way to insert a row into a table for a specified amount of time? Say 15mins, then after that time it gets dropped from the table automatically?


Copyright © 2005-08 www.BigResource.com, All rights reserved