本文目錄一覽:
如何修改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`)
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/282565.html