Home > Database > Mysql Tutorial > body text

查询sqlserver所有表并改变其架构

WBOY
Release: 2016-06-07 16:19:04
Original
941 people have browsed it

查询所有的数据库 select [name] from [sysdatabases] order by [name] 查询一个数据库中的所有表 select [id], [name] from [sysobjects] where [type] = 'u' 都知道[type] = 'u' 是用户表,[type] = 's'是系统表吧。 根据上个语句的查询结果然后再 查询一

   查询所有的数据库

  select [name] from [sysdatabases] order by [name]

  查询一个数据库中的所有表

  select [id], [name] from [sysobjects] where [type] = 'u'

  都知道[type] = 'u' 是用户表,[type] = 's'是系统表吧。

  根据上个语句的查询结果然后再

  查询一个表中的所有字段(我尝试不用[ID],而用[name]去查,,结果报错了)

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

  以上是查询所有表:

  以下是改变所有表架构:

  在数据库testDB中存在架构A及用户A,现将testDB数据库所属的用户由A改为B,同时删除用户A;架构也由A改为B,删除架构A,操作如下:

  1、创建用户B,再创建架构B;

  2、将架构A的权限赋给用户B,取消用户A拥有架构A的权限,删除用户A;

  3、将数据库的所有属于架构A的对象改为架构B,代码如下:

  ALTER SCHEMA [新架构名] TRANSFER 旧架构名。[数据库中的对象表或视图或存储过程]

  ALTER SCHEMA [B] TRANSFER A.[对象1]

  ALTER SCHEMA [B] TRANSFER A.[对象2]

  ALTER SCHEMA [B] TRANSFER A.[对象n]

  4、删除架构A.

  如:

  ALTER SCHEMA dbo TRANSFER danxiao1.ds_city1

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!