Showing posts with label dbo. Show all posts
Showing posts with label dbo. Show all posts

Thursday, March 22, 2012

Changing a SQL login from DBO to SA ( and back )

Hi,
Looking for a proper way to change a SQL login ( not a domain user ) from
DBO to SA ( and back if a curtain action has finished ) using TSQL.
This user is NOT connected to any role therefor sp_droprolemember/
sp_addrolemember is not appropriate.
Can you help me out guys?
G Kramerwould SETUSER or EXECUTE AS do?
Peter

Tuesday, March 20, 2012

Changing a column name

How can you change a Column name for MS SQL 2000 ?
something like :
ALTER TABLE [dbo].[MyTable]
OldName RENAME NewName
GO
thank youFrom BOL,

--This example renames the contact title column in the customers table to title.

EXEC sp_rename 'customers.[contact title]', 'title', 'COLUMN'|||thanks a lot|||So why does EM do this?

EXECUTE sp_rename N'dbo.myTable00.AccID', N'Tmp_AccID_new', 'COLUMN'
GO
EXECUTE sp_rename N'dbo.myTable00.Tmp_AccID_new', N'AccID_new', 'COLUMN'
GO|||Mainly for backward compatibility, I would guess. SQL 7.0 might not have supported renaming columns.|||EM is really a strange application
SELECT CASE doesn't work for example|||EM is really a strange application
SELECT CASE doesn't work for example

You mean in the View window...

ALL of that stuff should be done in Query Analyzer.

I like to see what EM does when you change a table..they usually try to provide the best practices approach.

For example, go change the order of a column, or drop a column in EM, and then save the script...

Know what it does? It doesn't use ALTER, and there's a very good reasonm for that.

Changing a BIT to an INT where there's a CONSTRAINT and a DEFAULT

A few weeks ago a client asked me to add a column to a table so I
created this script:

ALTER TABLE dbo.tblIndividual ADD fldRenewalStatus BIT NOT NULL
CONSTRAINT fldRenewalStatus_Default DEFAULT 0

Now they want to change it from a BIT to an INT, to store an enum.
Fair enough. However, no matter how much I wrangle with a script, I
can't find a reliable way to alter the column. I've mixed and matched
the following and nothing seems to work:

EXEC sp_unbindefault 'tblIndividual.fldRenewalStatus'

DROP DEFAULT DF_tblIndividual_fldRenewalStatus

ALTER TABLE tblIndividual
DROP CONSTRAINT fldRenewalStatus_Default

ALTER TABLE tblIndividual
DROP COLUMN fldRenewalStatus
GO

ALTER TABLE tblIndividual
ADD fldRenewalStatus int NOT NULL
CONSTRAINT fldRenewalStatus_Default DEFAULT 0

Thoughts?

Thanks

EdwardALTER the table to add a new INT column. Set the value of that column
based on the data in the BIT column. Alter the table to drop the BIT
column. Rename the INT column.

Roy Harvey
Beacon Falls, CT

On 2 Jan 2007 09:19:00 -0800, teddysnips@.hotmail.com wrote:

Quote:

Originally Posted by

>A few weeks ago a client asked me to add a column to a table so I
>created this script:
>
>ALTER TABLE dbo.tblIndividual ADD fldRenewalStatus BIT NOT NULL
>CONSTRAINT fldRenewalStatus_Default DEFAULT 0
>
>Now they want to change it from a BIT to an INT, to store an enum.
>Fair enough. However, no matter how much I wrangle with a script, I
>can't find a reliable way to alter the column. I've mixed and matched
>the following and nothing seems to work:
>
>EXEC sp_unbindefault 'tblIndividual.fldRenewalStatus'
>
>DROP DEFAULT DF_tblIndividual_fldRenewalStatus
>
>ALTER TABLE tblIndividual
>DROP CONSTRAINT fldRenewalStatus_Default
>
>ALTER TABLE tblIndividual
>DROP COLUMN fldRenewalStatus
>GO
>
>ALTER TABLE tblIndividual
>ADD fldRenewalStatus int NOT NULL
>CONSTRAINT fldRenewalStatus_Default DEFAULT 0
>
>
>Thoughts?
>
>Thanks
>
>Edward

|||On 2 Jan 2007 09:19:00 -0800, teddysnips@.hotmail.com wrote:

Quote:

Originally Posted by

>A few weeks ago a client asked me to add a column to a table so I
>created this script:
>
>ALTER TABLE dbo.tblIndividual ADD fldRenewalStatus BIT NOT NULL
>CONSTRAINT fldRenewalStatus_Default DEFAULT 0
>
>Now they want to change it from a BIT to an INT, to store an enum.
>Fair enough. However, no matter how much I wrangle with a script, I
>can't find a reliable way to alter the column. I've mixed and matched
>the following and nothing seems to work:


Hi Edward,

You can do as Roy suggests, or you can run the following script:

ALTER TABLE dbo.tblIndividual
DROP CONSTRAINT fldRenewalStatus_Default;

ALTER TABLE dbo.tblIndividual
ALTER COLUMN fldRenewalStatus INT NOT NULL;

ALTER TABLE dbo.tblIndividual
ADD CONSTRAINT fldRenewalStatus_Default DEFAULT 0 FOR fldRenewalStatus;

Running the ALTER COLUMN might take long if you have lots of data!

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis|||On Wed, 03 Jan 2007 00:06:18 +0100, Hugo Kornelis
<hugo@.perFact.REMOVETHIS.info.INVALIDwrote:

Quote:

Originally Posted by

>You can do as Roy suggests, or you can run the following script:


Much simpler, of course. Somehow I had the idea that bit would not
convert to int. Thanks for the diplomatic correction. 8-)

Roy|||Hugo Kornelis wrote:

Quote:

Originally Posted by

On 2 Jan 2007 09:19:00 -0800, teddysnips@.hotmail.com wrote:
>

Quote:

Originally Posted by

A few weeks ago a client asked me to add a column to a table so I
created this script:

ALTER TABLE dbo.tblIndividual ADD fldRenewalStatus BIT NOT NULL
CONSTRAINT fldRenewalStatus_Default DEFAULT 0

Now they want to change it from a BIT to an INT, to store an enum.
Fair enough. However, no matter how much I wrangle with a script, I
can't find a reliable way to alter the column. I've mixed and matched
the following and nothing seems to work:


>
Hi Edward,
>
You can do as Roy suggests, or you can run the following script:
>
ALTER TABLE dbo.tblIndividual
DROP CONSTRAINT fldRenewalStatus_Default;
>
ALTER TABLE dbo.tblIndividual
ALTER COLUMN fldRenewalStatus INT NOT NULL;
>
ALTER TABLE dbo.tblIndividual
ADD CONSTRAINT fldRenewalStatus_Default DEFAULT 0 FOR fldRenewalStatus;
>
Running the ALTER COLUMN might take long if you have lots of data!


Thanks Hugo - that worked a treat!

Edward

Thursday, March 8, 2012

change timestamp from null to not null

Hi,
I have a table with a timestamp column which allows nulls.
I wanted to
ALTER TABLE [dbo].[MyTbl] ALTER COLUMN [MyClmn] [timestamp]
NOT NULL
but it gives me msg 4927 - Cannot alter column 'MyClmn' to
be data type timestamp.
Is there any elegant/easy way around this?
--
Many thanks,
OskHi,
Would dropping the column and recreating it with the 'not
null' clause be the advisable way to do it?
--
Many thanks,
Osk
>--Original Message--
>Hi,
>I have a table with a timestamp column which allows nulls.
>I wanted to
>ALTER TABLE [dbo].[MyTbl] ALTER COLUMN [MyClmn] [timestamp]
>NOT NULL
>but it gives me msg 4927 - Cannot alter column 'MyClmn' to
>be data type timestamp.
>Is there any elegant/easy way around this?
>--
>Many thanks,
>Osk
>.
>|||Osk wrote:
> Hi,
> Would dropping the column and recreating it with the 'not
> null' clause be the advisable way to do it?
>
>> --Original Message--
>> Hi,
>> I have a table with a timestamp column which allows nulls.
>> I wanted to
>> ALTER TABLE [dbo].[MyTbl] ALTER COLUMN [MyClmn] [timestamp]
>> NOT NULL
>> but it gives me msg 4927 - Cannot alter column 'MyClmn' to
>> be data type timestamp.
>> Is there any elegant/easy way around this?
>> --
>> Many thanks,
>> Osk
>> .
If you need to preserve the data in the table, create a second table,
copy the data, change the first table DDL and then migrate the data
back.
--
David Gugick
Imceda Software
www.imceda.com|||Hi David,
Thanks for your answer. Can you please tell me why would I
lose any data except the old timestamp values (which seems
to be inevitable anyway) by dropping and
redefining/recreating the timestamp column?
--
Many thanks,
Osk
>--Original Message--
>Osk wrote:
>> Hi,
>> Would dropping the column and recreating it with the 'not
>> null' clause be the advisable way to do it?
>>
>> --Original Message--
>> Hi,
>> I have a table with a timestamp column which allows nulls.
>> I wanted to
>> ALTER TABLE [dbo].[MyTbl] ALTER COLUMN [MyClmn] [timestamp]
>> NOT NULL
>> but it gives me msg 4927 - Cannot alter column 'MyClmn' to
>> be data type timestamp.
>> Is there any elegant/easy way around this?
>> --
>> Many thanks,
>> Osk
>> .
>If you need to preserve the data in the table, create a
second table,
>copy the data, change the first table DDL and then migrate
the data
>back.
>--
>David Gugick
>Imceda Software
>www.imceda.com
>.
>|||anonymous@.discussions.microsoft.com wrote:
> Hi David,
> Thanks for your answer. Can you please tell me why would I
> lose any data except the old timestamp values (which seems
> to be inevitable anyway) by dropping and
> redefining/recreating the timestamp column?
>
I guess it really doesn't matter if you lose the data in the column.
--
David Gugick
Imceda Software
www.imceda.com|||Yes, I lose the timestamp data in the column, but the rest
of the table data should be remaining intact. And from this
perspective the result of using either the drop-
redefine/recreate method or the export/import method would
be the same, except that the latter takes more effort to
implement.
--
Thanks,
Osk
>--Original Message--
>anonymous@.discussions.microsoft.com wrote:
>> Hi David,
>> Thanks for your answer. Can you please tell me why would I
>> lose any data except the old timestamp values (which seems
>> to be inevitable anyway) by dropping and
>> redefining/recreating the timestamp column?
>I guess it really doesn't matter if you lose the data in
the column.
>--
>David Gugick
>Imceda Software
>www.imceda.com
>.
>

Saturday, February 25, 2012

change table ownership 2005

I have never been able to get this to work for 2005. Can anyone help
me troubleshoot my problem? I run this:
ALTER AUTHORIZATION ON db.table TO dbo;
GO
And get incorrect syntax near the keyword 'authorization'
I am supposed to run it as a query right?That's the correct syntax, yes. Does the following script run without error
for you:
--
use tempdb
go
create user auser without login
go
create table xyz (xxyyzz int)
go
alter authorization on xyz to auser
go
drop table xyz
go
drop user auser
go
--
--
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
<glayla@.gmail.com> wrote in message
news:1182458122.375047.227480@.k79g2000hse.googlegroups.com...
>I have never been able to get this to work for 2005. Can anyone help
> me troubleshoot my problem? I run this:
> ALTER AUTHORIZATION ON db.table TO dbo;
> GO
> And get incorrect syntax near the keyword 'authorization'
> I am supposed to run it as a query right?
>

Change table owner to dbo

How do I change the table owner back to dbo?
Never mind. I got it. I did not query MSDN correctly to find the answer.
sp_changeobjectowner
"sxa222" wrote:

> How do I change the table owner back to dbo?
|||sp_changeobjectowner [ @.objname = ] 'object' , [ @.newowner = ] 'owner'
MG
"sxa222" wrote:

> How do I change the table owner back to dbo?
|||Note that in 2005, this proc change both owner and schema, and also that the proc is deprecated. As
of 2005, use ALTER AUTHORIZATION to change owner of an object.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"sxa222" <sxa222@.discussions.microsoft.com> wrote in message
news:06384594-B178-42B8-B705-33E60E1F8B40@.microsoft.com...[vbcol=seagreen]
> Never mind. I got it. I did not query MSDN correctly to find the answer.
> sp_changeobjectowner
> "sxa222" wrote:

Change table owner to dbo

How do I change the table owner back to dbo?Never mind. I got it. I did not query MSDN correctly to find the answer.
sp_changeobjectowner
"sxa222" wrote:
> How do I change the table owner back to dbo?|||sp_changeobjectowner [ @.objname = ] 'object' , [ @.newowner = ] 'owner'
--
MG
"sxa222" wrote:
> How do I change the table owner back to dbo?|||Note that in 2005, this proc change both owner and schema, and also that the proc is deprecated. As
of 2005, use ALTER AUTHORIZATION to change owner of an object.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"sxa222" <sxa222@.discussions.microsoft.com> wrote in message
news:06384594-B178-42B8-B705-33E60E1F8B40@.microsoft.com...
> Never mind. I got it. I did not query MSDN correctly to find the answer.
> sp_changeobjectowner
> "sxa222" wrote:
>> How do I change the table owner back to dbo?

Change table owner to dbo

How do I change the table owner back to dbo?Never mind. I got it. I did not query MSDN correctly to find the answer.
sp_changeobjectowner
"sxa222" wrote:

> How do I change the table owner back to dbo?|||sp_changeobjectowner [ @.objname = ] 'object' , [ @.newowner = ] 'owne
r'
MG
"sxa222" wrote:

> How do I change the table owner back to dbo?|||Note that in 2005, this proc change both owner and schema, and also that the
proc is deprecated. As
of 2005, use ALTER AUTHORIZATION to change owner of an object.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"sxa222" <sxa222@.discussions.microsoft.com> wrote in message
news:06384594-B178-42B8-B705-33E60E1F8B40@.microsoft.com...[vbcol=seagreen]
> Never mind. I got it. I did not query MSDN correctly to find the answer.
> sp_changeobjectowner
> "sxa222" wrote:
>

Change Table from Namespace

I have a table like this : dbo.Table, and I recently create a namespace, and that table belongs there. So I want the table to be created on the new namespace, Namespace.Table, which is not big deal because I can script the table as a Create, and changes the [dbo].[table] to [Namespace].[Table]. But I need to import all the rows already on the old table. How can I achieve that?
Thanks

YOu can simply do a

INSERT INTO SchemaName.NewTable
SELECT * FROM SchemaOld.OldTable

HTH, Jens K. Suessmeyer.

http://www.sqlserver2005.de

|||Sweet! Thanks a lot for yur help!!

Tuesday, February 14, 2012

Change ownership on a table

Hi,
Does anyone know the syntax to change the ownership on a table? I want to change it from what it is now to the dbo owner.
Thanks!sp_changeobjectowner 'owner.tablename','newowner'|||Hi,
Thanks for the reply, it was actually something that my web host had to do for me, I tried what you suggested but the server wouldnt give permission, thanks for the tip =)|||Originally posted by krs74
Hi,
Thanks for the reply, it was actually something that my web host had to do for me, I tried what you suggested but the server wouldnt give permission, thanks for the tip =)

You should be the owner or sa to do that job

Change Ownership of Tables

I would like to change the ownership of the few tables from a user to dbo.
What is the best way to do this ?
Never done this before. What possible impact could this have ?
RK
Hi RK
Please read about sp_changeobjectowner in the Books Online
Any code that references object owners will have to be changed
HTH
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"RK73" <RK73@.discussions.microsoft.com> wrote in message
news:1EF21A6E-4B7A-4A6E-BE50-D4F75FC5FAFC@.microsoft.com...
>I would like to change the ownership of the few tables from a user to dbo.
> What is the best way to do this ?
> Never done this before. What possible impact could this have ?
> --
> RK
|||Even tho this is stated in BOL. sp_changeobjectowner This procedure removes
all existing permissions from the object. You will need to reapply any
permissions you want to keep after running sp_changeobjectowner.
For this reason, it is recommended that you script out existing permissions
before running sp_changeobjectowner. Once ownership of the object has been
changed, you may use the script to reapply permissions. You will need to
modify the object owner in the permissions script before running.
Sometimes overlooked
usually not twice.
"RK73" wrote:

> I would like to change the ownership of the few tables from a user to dbo.
> What is the best way to do this ?
> Never done this before. What possible impact could this have ?
> --
> RK

Change Ownership of Tables

I would like to change the ownership of the few tables from a user to dbo.
What is the best way to do this ?
Never done this before. What possible impact could this have ?
--
RKHi RK
Please read about sp_changeobjectowner in the Books Online
Any code that references object owners will have to be changed
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"RK73" <RK73@.discussions.microsoft.com> wrote in message
news:1EF21A6E-4B7A-4A6E-BE50-D4F75FC5FAFC@.microsoft.com...
>I would like to change the ownership of the few tables from a user to dbo.
> What is the best way to do this ?
> Never done this before. What possible impact could this have ?
> --
> RK|||Even tho this is stated in BOL. sp_changeobjectowner This procedure removes
all existing permissions from the object. You will need to reapply any
permissions you want to keep after running sp_changeobjectowner.
For this reason, it is recommended that you script out existing permissions
before running sp_changeobjectowner. Once ownership of the object has been
changed, you may use the script to reapply permissions. You will need to
modify the object owner in the permissions script before running.
Sometimes overlooked
usually not twice.
"RK73" wrote:

> I would like to change the ownership of the few tables from a user to dbo.
> What is the best way to do this ?
> Never done this before. What possible impact could this have ?
> --
> RK

Change Ownership of Tables

I would like to change the ownership of the few tables from a user to dbo.
What is the best way to do this ?
Never done this before. What possible impact could this have ?
--
RKHi RK
Please read about sp_changeobjectowner in the Books Online
Any code that references object owners will have to be changed
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"RK73" <RK73@.discussions.microsoft.com> wrote in message
news:1EF21A6E-4B7A-4A6E-BE50-D4F75FC5FAFC@.microsoft.com...
>I would like to change the ownership of the few tables from a user to dbo.
> What is the best way to do this ?
> Never done this before. What possible impact could this have ?
> --
> RK|||Even tho this is stated in BOL. sp_changeobjectowner This procedure removes
all existing permissions from the object. You will need to reapply any
permissions you want to keep after running sp_changeobjectowner.
For this reason, it is recommended that you script out existing permissions
before running sp_changeobjectowner. Once ownership of the object has been
changed, you may use the script to reapply permissions. You will need to
modify the object owner in the permissions script before running.
Sometimes overlooked
usually not twice.
"RK73" wrote:
> I would like to change the ownership of the few tables from a user to dbo.
> What is the best way to do this ?
> Never done this before. What possible impact could this have ?
> --
> RK

Change ownership for User Defined Data Types

Hello,

Does anybody know an easy way to change User Defined Data Types ownership to dbo, without dropping dependent objects?

I know that there is a st. proc sp_changeobject owner, but it does not deal with this particular db objects. Is there a similar st.procedure or script that would do the same operation?

Thank youThere are no dependent object to user-defined datatypes. If you try scripting out a table that was created with user-defined datatypes, you'll find it scripts the original datatype.
Neither do objects "inherit" changes made to User-defined datatype.
Thus: User-defined datatypes are candidates for the most useless and misleading features of SQL Server, perhaps exceeded only by the Maintenance Plan Wizard.|||Well, may be I expressed myself wrong. I was trying to change ownership for UDDTs, and I the only way I knew was to drop them and recreate as "dbo". But these UDDTs were already used by many tables and stored procedures. So I would need to drop those as well and then restore the data. Too much hassle.
Anyway, I have already found the solution. This is the script:

sp_configure 'Allow Update',1
Reconfigure WITH OVERRIDE

Update sysTypes set uid = user_id('dbo') Where name = …

sp_configure 'Allow Update',0
Reconfigure WITH OVERRIDE

Change ownership

Hello I'm trying to change the ownership using this command :

sp_changeobjectowner'govern.NA_WEB_SUBS_HITS','dbo'

and then I received this following error message :

Msg 15001, Level 16, State 1, Procedure sp_changeobjectowner, Line 75
Object 'govern.NA_WEB_SUBS_HITS' does not exist or is not a valid object for this operation.

Can anyone help please?

Thanks,

Stanley

You need to speicify the current owner on this object to change:

sp_changeobjectowner 'Dbobject', 'dbo'

|||

NOTE: sp_changeobjectowner has been deprecated in SQL Server 2005. I strongly recommend using the new DDL designed for changing ownership: ALTER AUTHORIZATION.

For more information please refer to BOL:

· ALTER AUTHORIZATION (Transact-SQL) http://msdn2.microsoft.com/en-us/library/ms187359.aspx

· sp_changeobjectowner (Transact-SQL) http://msdn2.microsoft.com/en-us/library/ms177519.aspx

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

What if the "current owner" does not exist? After a total system crash we made a db restore. All the objects belong to a sql user that does not exist anymore (different sid). What can we do now? http://support.microsoft.com/kb/275312/en-us has a good script generator but we got stuck "oldOwner.dbObject" does not exist!!!

Change ownership

Hello I'm trying to change the ownership using this command :

sp_changeobjectowner 'govern.NA_WEB_SUBS_HITS' , 'dbo'

and then I received this following error message :

Msg 15001, Level 16, State 1, Procedure sp_changeobjectowner, Line 75
Object 'govern.NA_WEB_SUBS_HITS' does not exist or is not a valid object for this operation.

Can anyone help please?

Thanks,

Stanley

You need to speicify the current owner on this object to change:

sp_changeobjectowner 'Dbobject', 'dbo'

|||

NOTE: sp_changeobjectowner has been deprecated in SQL Server 2005. I strongly recommend using the new DDL designed for changing ownership: ALTER AUTHORIZATION.

For more information please refer to BOL:

· ALTER AUTHORIZATION (Transact-SQL) http://msdn2.microsoft.com/en-us/library/ms187359.aspx

· sp_changeobjectowner (Transact-SQL) http://msdn2.microsoft.com/en-us/library/ms177519.aspx

Thanks a lot,

-Raul Garcia

SDE/T

SQL Server Engine

|||

What if the "current owner" does not exist? After a total system crash we made a db restore. All the objects belong to a sql user that does not exist anymore (different sid). What can we do now? http://support.microsoft.com/kb/275312/en-us has a good script generator but we got stuck "oldOwner.dbObject" does not exist!!!

Sunday, February 12, 2012

Change of Ownership??

I am having a problem with object ownership.
The person who setup the SQL Server setup the "dbo" account with his personal permissions. I need to change "dbo" so that the login name is the system account and not a personal account. Is this possible?

If this is not possible can I change the ownership of a system object?
I was able to change ownershipof user objects using the "sp_changeobjectowner" stored procedure, but it did not seem to work for system objects.

Any way around this?

- Ericdid you try sp_changedbowner? This would change the database ownership which I believe should change the system object ownership?>?|||The dbo user is so tightly "hardwired" into the database that I'd give the user a new login, change the ownership of their tables to that new user, and stop right there. I wouldn't even consider allowing the user to keep using dbo.

-PatP

Change Object Owner to dbo

Using SQL Server 7.0

Trying to change an objects ownership to dbo with

EXEC sp_changeobjectowner 'AssignInvoiceNumbers', 'dbo'

which gives the following error:

Server: Msg 15001, Level 16, State 1, Procedure sp_changeobjectowner,
Line 26
AssignInvoiceNumbers does not exist.

which it does.

Any help would be greatly appreciated

--

Nath

(Email mangling obvious)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Nath Wilson <chanester@.a0l.com> wrote in message news:<3f2f79f2$0$192$75868355@.news.frii.net>...
> Using SQL Server 7.0
> Trying to change an objects ownership to dbo with
> EXEC sp_changeobjectowner 'AssignInvoiceNumbers', 'dbo'
> which gives the following error:
> Server: Msg 15001, Level 16, State 1, Procedure sp_changeobjectowner,
> Line 26
> AssignInvoiceNumbers does not exist.
> which it does.
> Any help would be greatly appreciated
> --
> Nath
> (Email mangling obvious)
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

EXEC sp_changeobjectowner 'CurrentOwner.AssignInvoiceNumbers', 'dbo'

Simon

Change object all object onwer

I have a script like below to change all the object owner from "xxxxx"
to "dbo".
==================================== declare @.name varchar(250)
declare @.olduser varchar(250)
declare @.newuser varchar(250)
declare @.sp_str varchar(250)
set @.olduser = 'xxxxx.'
set @.newuser = 'dbo'
declare cursor1 cursor for
select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
uid of 'xxxxx')
open cursor1
fetch next from cursor1 into @.name
WHILE @.@.FETCH_STATUS = 0
--while begin transaction
begin
set @.sp_str = @.olduser + @.name
exec sp_changeObjectOwner @.sp_str,@.newuser
fetch next from cursor1 into @.name
end
--commit transaction
close cursor1
deallocate cursor1
====================================
How if I want to change only a particular database, don't care what's
the existing object owner is, but just change all the object owner to
"xxxxx"?
Does anyone have good script to change that?
Or any way to modify the above script to acomplish that?
Peter CCHChange one line:
select sysobjects.name from sysobjects where sysobjects.xtype = 'u' and
sysobjects.uid NOT IN (SELECT sysusers.uid FROM sysusers WHERE sysusers.name
<> @.newuser)
Regards
--
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Peter CCH" <petercch.wodoy@.gmail.com> wrote in message
news:1133099207.669540.204000@.g14g2000cwa.googlegroups.com...
>I have a script like below to change all the object owner from "xxxxx"
> to "dbo".
> ====================================> declare @.name varchar(250)
> declare @.olduser varchar(250)
> declare @.newuser varchar(250)
> declare @.sp_str varchar(250)
> set @.olduser = 'xxxxx.'
> set @.newuser = 'dbo'
> declare cursor1 cursor for
> select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
> uid of 'xxxxx')
> open cursor1
> fetch next from cursor1 into @.name
> WHILE @.@.FETCH_STATUS = 0
> --while begin transaction
> begin
> set @.sp_str = @.olduser + @.name
> exec sp_changeObjectOwner @.sp_str,@.newuser
> fetch next from cursor1 into @.name
> end
> --commit transaction
> close cursor1
> deallocate cursor1
> ====================================> How if I want to change only a particular database, don't care what's
> the existing object owner is, but just change all the object owner to
> "xxxxx"?
> Does anyone have good script to change that?
> Or any way to modify the above script to acomplish that?
>
>
> Peter CCH
>

Change object all object onwer

I have a script like below to change all the object owner from "xxxxx"
to "dbo".
====================================
declare @.name varchar(250)
declare @.olduser varchar(250)
declare @.newuser varchar(250)
declare @.sp_str varchar(250)
set @.olduser = 'xxxxx.'
set @.newuser = 'dbo'
declare cursor1 cursor for
select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
uid of 'xxxxx')
open cursor1
fetch next from cursor1 into @.name
WHILE @.@.FETCH_STATUS = 0
--while begin transaction
begin
set @.sp_str = @.olduser + @.name
exec sp_changeObjectOwner @.sp_str,@.newuser
fetch next from cursor1 into @.name
end
--commit transaction
close cursor1
deallocate cursor1
====================================
How if I want to change only a particular database, don't care what's
the existing object owner is, but just change all the object owner to
"xxxxx"?
Does anyone have good script to change that?
Or any way to modify the above script to acomplish that?
Peter CCH
Change one line:
select sysobjects.name from sysobjects where sysobjects.xtype = 'u' and
sysobjects.uid NOT IN (SELECT sysusers.uid FROM sysusers WHERE sysusers.name
<> @.newuser)
Regards
Mike Epprecht, Microsoft SQL Server MVP
Zurich, Switzerland
IM: mike@.epprecht.net
MVP Program: http://www.microsoft.com/mvp
Blog: http://www.msmvps.com/epprecht/
"Peter CCH" <petercch.wodoy@.gmail.com> wrote in message
news:1133099207.669540.204000@.g14g2000cwa.googlegr oups.com...
>I have a script like below to change all the object owner from "xxxxx"
> to "dbo".
> ====================================
> declare @.name varchar(250)
> declare @.olduser varchar(250)
> declare @.newuser varchar(250)
> declare @.sp_str varchar(250)
> set @.olduser = 'xxxxx.'
> set @.newuser = 'dbo'
> declare cursor1 cursor for
> select name from sysobjects where xtype = 'u' and uid = 5 -- (5 - the
> uid of 'xxxxx')
> open cursor1
> fetch next from cursor1 into @.name
> WHILE @.@.FETCH_STATUS = 0
> --while begin transaction
> begin
> set @.sp_str = @.olduser + @.name
> exec sp_changeObjectOwner @.sp_str,@.newuser
> fetch next from cursor1 into @.name
> end
> --commit transaction
> close cursor1
> deallocate cursor1
> ====================================
> How if I want to change only a particular database, don't care what's
> the existing object owner is, but just change all the object owner to
> "xxxxx"?
> Does anyone have good script to change that?
> Or any way to modify the above script to acomplish that?
>
>
> Peter CCH
>