banner
ximalaya

ximalaya

这里是openkava 的blog,关注程序开发的一切技术。 ZZ 表示转载的文章,如涉及版权,请和我联系删除。 在这里你可以看到关于以下技术的文章: 移动开发技术,ANDROID ,IOS,WINDOWS PHONE平台开发,企业ERP开发,动态脚本PYTHON ,OPENGL ES 3D技术,游戏开发技术,HTML5 ,JAVASCRIPT ,MYSQL,AMAZON EC2 ,GOOGLE GAE ,GOOGLE CLOUD SQL 等 。 本站发展历程: 2010年,正式把所有的blog移到这里,租用godaddy的空间,记录生活和工作上的一些心得。 下面是关于我的个人介绍,写在这里权当凑字数啦。 职业:软件开发,开发经验6年,管理经验3年; 工作上使用的技术:C#, SQL SERVER 个人使用的技术:PYTHON,PHP, CSS, JAVA ,ANDROID ,object-c 等等 联系我请发邮件:<a href="http://blog.openkava.com/openkava@gmail.png"><img class="alignnone size-full wp-image-96" title="邮箱" src="http://blog.openkava.com/openkava@gmail.png" alt="" width="174" height="24" /></a>

zz 修改MS SQL2000資料庫的所有者

http://www.cnblogs.com/wantingqiang/archive/2008/12/14/1354738.html

有些時候,一個資料庫的管理員,需要將幾個不同的資料庫內的資料合併到一起,如果幾個資料庫的結構基本相同,只需新建一個資料庫,將其它幾個資料庫內的物件複製並追加到新資料庫內並做細微調整即可達到目的,但是,不同的資料庫可能存在不同的使用者帳號,資料庫物件 —— 譬如:表,儲存過程及視圖等 —— 的所有者也可能不同,這樣,在匯入資料時,系統會將同名但不同所有者的資料庫物件識別為不同的物件,會在目標庫中新建物件而非追加,並且會因為目標庫中沒有相應的使用者帳號而報使用者不存在的錯,那麼,統一資料庫物件的所有者就很必要了。

還是老習慣,下面給出更改資料庫表,儲存過程及視圖所有者的 SQL 腳本,需要說明的是,這段腳本同樣可以用於將資料庫物件的所有者由 DBO 使用者更改為其它指定的使用者,使用的方法為:將 YourUserName 更改為 DBO,在原有 DBO 的位置輸入想要指定的使用者帳號名稱,執行即可,當然,這段腳本代碼在使用的時候是很靈活的,並非只針對關於 DBO 與其它指定帳號之間的更改,實踐一下就自然明白了

  1. 修改表的所有者

declare @tn varchar(120)

declare table_cursor cursor for
Select '[' + sysusers.name + '].' + sysobjects.name AS table_name
FROM sysobjects INNER JOIN sysusers ON sysobjects.uid = sysusers.uid
Where sysusers.name = 'YourUserName' AND sysobjects.type = 'U'

open table_cursor
fetch next from table_cursor into @tn

while @@FETCH_STATUS = 0
begin
exec sp_changeobjectowner @tn, 'dbo'

fetch next from table_cursor into @tn
end

close table_cursor
deallocate table_cursor

  1. 修改儲存過程的所有者

declare @tn varchar(120)

declare procedure_cursor cursor for
Select '[' + sysusers.name + '].' + sysobjects.name AS procedure_name
FROM sysobjects INNER JOIN sysusers ON sysobjects.uid = sysusers.uid
Where sysusers.name = 'YourUserName' AND sysobjects.type = 'P'

open procedure_cursor
fetch next from procedure_cursor into @tn

while @@FETCH_STATUS = 0
begin
exec sp_changeobjectowner @tn, 'dbo'

fetch next from procedure_cursor into @tn
end

close procedure_cursor
deallocate procedure_cursor

  1. 修改視圖的所有者

declare @tn varchar(120)

declare view_cursor cursor for
Select '[' + sysusers.name + '].' + sysobjects.name AS view_name
FROM sysobjects INNER JOIN sysusers ON sysobjects.uid = sysusers.uid
Where sysusers.name = 'YourUserName' AND sysobjects.type = 'V'

open view_cursor
fetch next from view_cursor into @tn

while @@FETCH_STATUS = 0
begin
exec sp_changeobjectowner @tn, 'dbo'

fetch next from view_cursor into @tn
end

close view_cursor
deallocate view_cursor

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。