批量修改: EXEC sp_MSforeachtable 'exec sp_changeobjectowner ''?'',''dbo'' ' 单个修改: exec sp_changeobjectowner '要改的表名','dbo' 只有所有者才能更改表的所有者 有很服务器: 消息 15001,级别 16,状态 1,过程 sp_changeobjectowner,行 38 对
批量修改:
EXEC sp_MSforeachtable 'exec sp_changeobjectowner ''?'',''dbo'' '
单个修改:
exec sp_changeobjectowner '要改的表名','dbo'
只有所有者才能更改表的所有者
有很服务器: 消息 15001,级别 16,状态 1,过程 sp_changeobjectowner,行 38
对象 'user' 不存在或不是对此操作有效的对象。
多表是导入的 一些所有者的密码都不记得就会产生
觉得是不是没有原来的所有者 我加了一下 嘿嘿 正常!
exec sp_changeobjectowner '表所有者.要改的表名','dbo'
就不需表的所有者才能修改了
补充:
--执行这个语句,就可以把当前库的所有表的所有者改为dbo
exec sp_msforeachtable 'sp_changeobjectowner ''?'', ''dbo'''
--如果是要用户表/存储过程/视图/触发器/自定义函数一齐改,则用游标(不要理会错误提示)
declare tb cursor local for
select 'sp_changeobjectowner ''['+replace(user_name(uid),']',']]')+'].['
+replace(name,']',']]')+']'',''dbo'''
from sysobjects
where xtype in('U','V','P','TR','FN','IF','TF') and status>=0
open tb
declare @s nvarchar(4000)
fetch tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch tb into @s
end
close tb
deallocate tb
go
1. sp_changeobjectowner
更改当前数据库中对象的所有者。
语法
sp_changeobjectowner [ @objname = ] 'object' , [ @newowner = ] 'owner'
参数
[@objname =] 'object'
当前数据库中现有的表、视图或存储过程的名称。object 的数据类型为 nvarchar(517),没有默认值。object 可用现有对象所有者限定,格式为 existing_owner.object。
[@newowner =] 'owner'
即将成为对象的新所有者的安全帐户的名称。owner 的数据类型为 sysname,没有默认值。owner 必须是当前数据库中有效的 Microsoft? SQL Server? 用户或角色或 Microsoft Windows NT? 用户或组。指定 Windows NT 用户或组时,请指定 Windows NT 用户或组在数据库中已知的名称(用 sp_grantdbaccess 添加)。
返回代码值
0(成功)或 1(失败)
注释
对象所有者(或拥有对象的组或角色的成员)对对象有特殊的权限。对象所有者可以执行任何与对象有关的 Transact-SQL 语句(例如 Insert、Update、Delete、Select 或 EXECUTE),也可以管理对象的权限。
如果拥有对象的安全帐户必须要除去,但同时要保留该对象,请使用 sp_changeobjectowner 更改对象所有者。该过程从对象中删除所有现有权限。在运行 sp_changeobjectowner 之后,需要重新应用要保留的任何权限。
由于这个原因,建议在运行 sp_changeobjectowner 之前,编写现有权限的脚本。一旦更改了对象的所有权,可能要使用该脚本重新应用权限。在运行该脚本之前需要在权限脚本中修改对象所有者。有关编写数据库脚本的更多信息,请参见编写数据库文档和脚本。
可以使用 sp_changedbowner 更改数据库的所有者。
权限
只有 sysadmin 固定服务器角色和 db_owner 固定数据库角色成员,或既是 db_ddladmin 固定数据库角色又是 db_securityadmin 固定数据库角色的成员,才能执行 sp_changeobjectowner。
示例
下面的示例将 authors 表的所有者改为 Corporate\GeorgeW。
EXEC sp_changeobjectowner 'authors', 'Corporate\GeorgeW'
请参见
改变数据库所有者:sp_changedbowner
------------------------------以上摘自sql server 的联机丛书
注意:
使用sqlserver2000改变对象(object)(如Table,SP,View)的所有者(owner)时,需要注意一点:
如果对象改变前的owner为dbo,则直接用:exec sp_changeobjectowner 对象名,新的所有者名就可以成功。如果再需要改变该对象的所有者,则要用如下语法:
exec sp_changeobjectowner "[所有者].[对象名]",新的所有者。注意,双引号不可省略,否则提示objectname does not exist。
EXEC sp_changeobjectowner 'cqadmin.authors', 111
2.建与原表结构相同表,然后把数据从原表插入到新表,操作方法:
在sql server企业管理器中选择原表点右键,选择“所有任务/生存SQL脚本”,保存生成的脚本,在脚本中把表的原所有者改成新所有者。然后再把该脚本运行一遍,数据库中就新生成了一个表,所有者是新所有者,原来的表还在数据库中没有被替换。新表和旧表 表名相同,所有者不同,此时的新表中没有数据。
然后再运行下面的语句往新表中插入数据:
Insert INTO CQAdmin.m_actiondef //新所有者.新表名
Select *
FROM RegaltecDefSchema. CQAdministrator.m_actiondef // 数据库名.旧所有者.旧表名
运行完了就做完了,可以把旧表删掉,也可以留着。

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment
