Query all SQL Server tables and change their architecture

Source: Internet
Author: User

Query all databases

Select [name] from [sysdatabases] order by [name]

Query all tables in a database

Select [id], [name] from [sysobjects] where [type] = 'U'

We all know that [type] = 'U' is a user table, and [type] = 's' is a system table.

Based on the query result of the previous statement

Query all the fields in a table (I tried to query the fields using [name] instead of [ID]. An error is returned)

Select [name] from [syscolumns] where [id] = 1931153925

The preceding statements are used to query all tables:

Change the architecture of all tables as follows:

Architecture A and user A exist in the Database testDB. Now, the user of the database testDB is changed from A to B, and user A is deleted. The architecture is also changed from A to B, and schema A is deleted, the procedure is as follows:

1. create user B and then create architecture B;

2. Grant schema A permissions to user B, cancel user A's permissions on schema A, and delete user;

3. Change all database objects belonging to architecture A to architecture B. The Code is as follows:

Alter schema [new SCHEMA name] Old transfer schema name. [Object tables, views, or stored procedures in databases]

Alter schema [B] TRANSFER A. [object 1]

Alter schema [B] TRANSFER A. [object 2]

Alter schema [B] TRANSFER A. [object n]

4. Delete architecture.

For example:

Alter schema dbo TRANSFER danxiao1.ds _ city1

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.