首页
登录 | 注册

创建及删除管理员用户(3种数据库)

 

1、SQLSERVER
创建用户
sp_addlogin @loginame = N'commonuser'
  , @passwd = N'Admin123'
  , @defdb = N'master'
  , @sid = null
  , @encryptopt = null
GO
EXEC sp_addsrvrolemember N'commonuser', N'sysadmin'

删除用户
sp_droplogin @loginame = N'commonuser'
GO

查看数据库版本:
select @@version

2、mysql
创建用户

create user commonuser@'%' identified by 'Admin123';
grant all on *.* to commonuser@'%' identified by 'Admin123';

create user commonuser@'localhost' identified by 'Admin123';
grant all on *.* to commonuser@'localhost' identified by 'Admin123';

删除用户
drop user commonuser@'localhost';
drop user commonuser@'%';

3、ORACLE

删除用户:

declare
  v_cnt number;
  sqlstr varchar2(512);
begin
  sqlstr:='drop user COMMONUSER cascade';
  execute immediate sqlstr;
end;
/

创建用户:

declare
  v_cnt number;
  sqlstr varchar2(512);
begin
  select count(USERNAME) into v_cnt from dba_users where username='COMMONUSER';
  if v_cnt=0 then
    sqlstr:='create user COMMONUSER identified by "******" default tablespace SYSTEM temporary tablespace TEMP quota unlimited on SYSTEM';
    execute immediate sqlstr;
    sqlstr:='grant dba to COMMONUSER';
    execute immediate sqlstr;
  end if;
end;

 



2020 jeepxie.net webmaster#jeepxie.net
10 q. 0.009 s.
京ICP备10005923号