How does SQL SERVER modify the architecture of tables and stored procedures in batches?

Source: Internet
Author: User

SQL 2005 how to modify the architecture of tables and stored procedures in batches
* ** First, you need to add a new architecture owner to the architecture item in the security selection of the database to be modified.
1. Let's talk about it first.How to modify the architecture of stored procedures in batches in SQL 2005.
Run the following SQL statement to copy the execution result.
Select 'alter schema DBO transfer '+ S. Name +'. '+ P. Name
From SYS. Procedures P inner join SYS. schemas s on p. schema_id = S. schema_id
Where S. Name = 'old schema name'

2. Let's talk about it.How to modify the architecture of tables in batches in SQL 2005.
Method 1: execute the following SQL statement to copy the execution result. Batch execution is acceptable.
Declare @ name sysname
Declare csr1 cursor
For
Select table_name from information_schema.tables
Open csr1
Fetch next from csr1 into @ name
While (@ fetch_status = 0)
Begin
Set @ name = 'old architecture name. '+ @ name
Print 'alter schema DBO (new schema name) transferer' + @ name
Fetch next from csr1 into @ name
End
Close csr1
DEALLOCATE csr1

Method 2: Use the system stored procedure sp_MSforeachtable
EXEC sp_MSforeachtable @ command1 = "EXEC SP_ChangeObjectOwner '? ', 'New architecture name '"

 

Note: you must first Delete the schema owned by the user or change the owner of the schema. Otherwise, the system prompts "the database subject has a schema in the database and cannot be deleted ";
Each database user corresponds to a system login account, and each architecture can only be assigned to one user, so it is not possible to directly Delete the user's architecture;
You can pay the db_owner architecture TO dbo in the user ing (or execute alter authorization on schema: db_owner TO dbo );
Then you can delete the previous user.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.