本文目录一览:
如何修改mysql主键的值为自增
如何修改mysql主键的值为自增
CREATE TABLE `t` (
...
) AUTO_INCREMENT=制定开始ID
如果用Navicat 更加简单
怎么修改mysql主键自增的值
主键-列属性-标识规范-标识增量,我这个是sql,你看看mysql是不是差不多
我想在mysql中用触发器修改主键ID 的值
use
[你的数据库]
go
create
trigger
name
on
[table]
after
delete
as
begin
--定义游标,使你逐个往下找个ID,并执行update修改
declare
@flag
int
select
@flag=ID
from
deleted
declare
[cursorname]
cursor
for
select
ID
from
[table]
where
ID@flag
open
[cursorname]
fetch
next
from
[cursorname]
update
[table]
set
ID=ID+1
where
ID=fetch
next
from
[cursorname]
WHILE
@@FETCH_STATUS
=
begin
update
[table]
set
ID=ID+1
where
ID=fetch
next
from
[cursorname]
close
[cursorname]
DEALLOCATE
authors_cursor
end
end
如何修改mysql主键(id)的值为自增
-- 创建表
CREATE TABLE `t2` (
`code` varchar(100) DEFAULT NULL,
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- 添加主键
ALTER TABLE `t2` ADD COLUMN `ID` int(10) NOT NULL AUTO_INCREMENT AFTER `code`,ADD PRIMARY KEY (`id`)