更改角色名以及删除帐号的SQL程序

来源: 作者: 点击:
以下是代码:
--这个程序用于更改角色名字。
use muonline
declare @oldname nvarchar(10),@newname nvarchar(10)
--在单引号里面输入要查询的角色名,前是老名字,后是新名字。
set @oldname = '老名字'
set @newname = '新名字'

if @newname in (select name from character where name=@newname)
print '数据库里已有相同角色名,不进行更名操作!'
else
begin
update accountcharacter set gameid1 = @newname where gameid1 = @oldname
update accountcharacter set gameid2 = @newname where gameid2 = @oldname
update accountcharacter set gameid3 = @newname where gameid3 = @oldname
update accountcharacter set gameid4 = @newname where gameid4 = @oldname
update accountcharacter set gameid5 = @newname where gameid5 = @oldname
update accountcharacter set gameidc = @newname where gameidc = @oldname

update character set name = @newname where name = @oldname
update guild set g_master = @newname where g_master = @oldname
update guildmember set name = @newname where name = @oldname
update optiondata set name = @newname where name = @oldname
end

[Ctrl+A 全部选择]



以下是代码:
--这个程序是用来根据一个角色名删除它所属的帐号以及帐号下的所有角色/盟/仓库等所有相关信息的
--数据一经删除无法恢复,请谨慎使用

use muonline
declare @i int,@varid nvarchar(10), @varname nvarchar (10),@vargn nvarchar(10)

--在单引号里面输入要查询的角色名
set @varname = '角色名字'

--查出帐号
select @varid = accountid from character where name = @varname

--根据帐号下的每个角色,删除盟数据.如果是盟主,删除整个盟的数据.
set @i=1
while (@i < 6)
begin
set @varname = ''
set @vargn = ''
select @varname =
case when @i=1 then gameid1
when @i=2 then gameid2
when @i=3 then gameid3
when @i=4 then gameid4
when @i=5 then gameid5
end
from accountcharacter where id = @varid
if @varname = '' break

select @vargn = g_name from guild where g_master = @varname

if @vargn = ''
delete from guildmember where Name = @varname
else
begin
delete from guild where g_master = @varname
delete from guildmember where g_name = @vargn
end

set @i = @i + 1
end
--以下删除与帐号相关的所有信息
delete from accountcharacter where id = @varid
delete from character where accountid = @varid
delete from memb_info where memb___id = @varid
delete from vi_curr_info where memb___id = @varid
delete from warehouse where accountid = @varid
栏目列表