首页 > 编程知识 正文

修改mysql数据库中主键的值(数据库修改主键的方法)

时间:2023-12-24 12:05:56 阅读:321228 作者:TIII

本文目录一览:

如何修改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`)

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。