insert into user (username,password) VALUES ('); //获取刚插入的自增长id的值 select last_insert_id(); 在MySQL中,使用auto_increment类型的id字段作为表的主键,并用它作为其他表的外键,形成“主从表结构”,这是数据库设计中常见的用法.但是在具体生成id的时候,我们的操作顺序一般是:先在主表中插入记录,然后获得自动生成的id,以它为基础插入从表的记录.这里面有个困难,就是插入主表记录后,如何获得它对应的i
python插入记录后取得主键id的方法(cursor.lastrowid和conn.insert_id()) 参考:https://blog.csdn.net/qq_37788558/article/details/78151972 python插入记录后获取最后一条数据的id #!/usr/bin/python # import MySQL module import MySQLdb # get user input name = raw_input("Please enter a name
postgresql不支持last_insert_id()方法,恶心到啦: 不过还好它有其他的解决方案: 创建一个测试数据表: CREATE TABLE test.test18 ( id serial NOT NULL, ddd character varying ) 一.先过去不重复的主键id,然后再插入 获取他的Sequence,select nextval('test.test18_id_seq'),然后再插入即可! 二.返回主键id insert into test.test18 (dd
create procedure sp_AddUser1@Name nvarchar(200), @Remark nvarchar(200),@Flag int as begin declare @id int insert into User(Name,Remark,Flag) values(@Name, @Remark,@Flag)set @id = scope_identity()update User set Sort=@id where ID=@idend create procedu