1024programmer News Mysql adds and returns the corresponding id, inserts a record in mysql and returns the record id

Mysql adds and returns the corresponding id, inserts a record in mysql and returns the record id

Insert a record in mysql and return the record id

1.select max(id) from user;

2.select last_insert_id() as id from user limit 1;

(The return id of this test has always been 0, a bit of a problem)

3. Stored process

1)

In oracel

create sequence seqID

minvalue 1

maxvalue 999999999999999999999999999

start with 1

increment by 1

increment by 1

p>

nocache

order;

create or replace procedure sp_insert(aName int,rst out int) is

begin

insert into tablename(id,name) values(seqID.nextval,aName);

rst:=seqID.currval;

end;

2) Implementation in mysql

DELIMITER $$

DROP PROCEDURE IF EXISTS `test` $$

CREATE DEFINER=& #96;root`@`localhost`PROCEDURE`test`(in name varchar(100),out oid int)

BEGIN

BEGIN

insert into user(loginname) values(name);

select max(id) from user into oid;

select oid;

END $$

DELIMITER ;

Then execute

call test('gg',@id);

Just return id

Related documents :

Administration management

Kill a Thread End a thread

mysql > KILL 999;

Optimize Table optimize table

mysql > OPTIMEZE TABLE foo;

Reload Users Permissions refresh MySQL system permission related tables

mysql > FLUSH PRIVILEGES;

Repair Table Repair Table

mysql &gt  …

destroy-method=”close”>

Create database:

mysql>create database test;

Query OK, 1 row affected (0.02 sec)

Create Database table :

mysql>use test;

Database changed

create database table :

myaql> create table user(SID VARCHAR(11), name VARCHAT(6) );

Query OK, 0 rows affected (0.08 sec)

Insert record:

mysql>insert int use ……

The installed OS is Solaris10, and the mysql version is 5.1.38

1. Use the RPM package for installation

p>

First, you can download the corresponding version of the rpm package from the installation CD or the mysql website as follows :

MySQL-server-community-5.1.38-0.rhel5.i386 .rpm

MySQL-client-community-5.1.38-0.rhel5.i386.rpm

Then we can use the rpm command……

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/mysql-adds-and-returns-the-corresponding-id-inserts-a-record-in-mysql-and-returns-the-record-id/

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索