Home Database Mysql Tutorial SQL SERVER 2005/2008 中关于架构的理解(一)

SQL SERVER 2005/2008 中关于架构的理解(一)

Jun 07, 2016 pm 05:38 PM
server about Architecture understand

SQLSERVER2005/2008 中关于架构的理解(一) 在一次的实际工作中碰到以下情况,在SQLSERVER2008中,新建了一个新用户去访问几张由其他用户创建的表,但是无法进行查询,提示对象名'CustomEntry'无效。。当带上了架构名称之后(如cus.CustomEntry),却又能查询到

SQL SERVER 2005/2008 中关于架构的理解(一)

 

       在一次的实际工作中碰到以下情况,在 SQL SERVER 2008中,新建了一个新用户去访问几张由其他用户创建的表,但是无法进行查询,提示“对象名'CustomEntry' 无效。”。当带上了架构名称之后(如“cus.CustomEntry”),却又能查询到表中的数据了,但是查询语句是已经写死在了应用程序中的,如果要进行更改,就有很大的工作量, 这是一件很郁闷的事情。于是想从数据库层面上解决此问题,在查询了大量的资料之后,对于SQL SERVER中的架构有所了解,并解决以上问题。

      下面来说说,自己对SQL SERVER 中架构的理解,并在此记录,以备查。

      在SQL SERVER 2000中不存在上面所说的问题,那为什么在2008中会出现这样的事情,这样的设置可以带来哪些好处?导致这一问题的原因主要在于SQL SERVER 2005/2008中多了一个新的概念——架构。

       首先,我们来看一下微软对架构的官方定义:架构(Schema)是形成单个命名空间的数据库实体的集合。命名空间是一个集合,其中每个元素的名称都是唯一的。在这里,我们可以将架构看成一个存放数据库中对象的一个容器。

      架构实际上在SQL SERVER 2000中就已经存在,在SQL SERVER 2000中数据库用户和架构是隐式连接在一起的, 每个数据库用户都是与该用户同名的架构的所有者。当我们使用查询分析器去查询一个表的时候,一个完整的表的名称应该包括服务器名.数据库名.用户名.对象名,而在SQL SERVER 2005/2008中一个表的完全限定名称应该为服务器名.数据库名.架构名.对象名

      在SQL SERVER 2000中的完全限定名称中的“用户名”也是数据库中的用户,也是“架构名”。假如有一个账户df在test数据库中创建了一张表tb1的时候,在查询分析器中应该输入的查询语句为select * from test.df.tb1,也就是说,在SQL SERVER  2000中一张表所属的架构默认就是表的创建者的登录名称,用户可以修改他所创建的所有数据库对象。但在2008中已经将用户和其创建对象所属关联取消了,而加入了一个全新的架构体系。

 

用户架构分离的好处

那么将架构与数据库用户分离对管理员和开发人员而言有什么好处呢?

 

1. 架构管理与用户管理分开。多个用户可以通过角色(role)或组(Windows groups)成员关系拥有同一个架构。在SQL SERVER 2005/2008 中,每个数据库中的固定数据库角色都有一个属于自己的架构,如果我们创建一个表,给它指定的架构名称为 db_ddladmin,那么任何一个属于db_ddladmin中的用户都是可以去查询、修改和删除属于这个架构中的表,但是不属于这个组的用户是没有对这个架构中的表进行操作的权限,有一点必须注意,db_dbdatareader组的成员可以查看所有数据库中的表,db_dbdatawriter组成员可以修改所有数据库中 的表,db_owner组成员可以对数据库所有表进行所有操作,这几个组的成员可以通过角色获取到在数据库中的特殊权限。

2. 在创建数据库用户时,可以指定该用户账号所属的默认架构。 ( 建议大家指定)

3. 删除数据库用户变得极为简单。在 SQL Server 2000 中,用户(User)和架构是隐含关联的,即每个用户拥有与其同名的架构。因此要删除一个用户,必须先删除或修改这个用户所拥有的所有数据库对象,就比如 一个员工要离职要删除他的账户的时候,还得将他所创建的表和视图等都删除,影响过大。SQL SERVER 2005/2008将架构和对象者分离后就不在存在这样的问题,删除用户的时候不需要重命名该用户架构所包含的对象,在删除创建架构所含对象的用户后,不再需要修改和测试显式引用这些对象的应用程序。

 

4. 共享缺省架构使得开发人员可以为特定的应用程序创建特定的架构来存放对象,这比仅使用管理员架构(DBO schema)要好。

5. 在架构和架构所包含的对象上设置权限(permissions)比以前的版本拥有更高的可管理性。

6. 区分不同业务处理需要的对象,例如,我们可以把公共的表设置成pub的架构,把销售相关的设置为sales,这样管理和访问起来更容易。

大多数用户在创建对象的时候习惯直接输入对象名而将对象的架构名称省略,在2005/2008 中,,会给用户创建的这样的表加上一个缺省的架构,用户如果没有对自己的默 认架构做设置,那缺省架构就是dbo,也就是说,如果一个db_ddladmin的成员在数据库中创建一个没有加上架构名称的表,这个表在数据库中的完整 名称应该是dbo.表名,创建者在数据库中如果不是属于其它特殊组的成员,是不能对自己创建的表进行任何修改和查询的,那就相当于把自己赚的钱存进了别人的银行卡,自己却取不出来。

 

 

7 若不指定默认架构,则为DBO,为了向前兼容,早期版本中的对象迁移到新版本中,早期版本中没有架构的概念的。所以就该对象的架构名就是dbo.在SQL Server 2008中,DBO就是一个架构

8 当查找对象时,先找与用户默认架构相同的架构下的对象,找不到再找DBO的对象

第8点有点难理解,我们来看一张图,通过这张图,大家应该能很显示的理解这一点:

(上图来自网络)

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the architecture and working principle of Spring Data JPA? What is the architecture and working principle of Spring Data JPA? Apr 17, 2024 pm 02:48 PM

SpringDataJPA is based on the JPA architecture and interacts with the database through mapping, ORM and transaction management. Its repository provides CRUD operations, and derived queries simplify database access. Additionally, it uses lazy loading to only retrieve data when necessary, thus improving performance.

How to install, uninstall, and reset Windows server backup How to install, uninstall, and reset Windows server backup Mar 06, 2024 am 10:37 AM

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

1.3ms takes 1.3ms! Tsinghua's latest open source mobile neural network architecture RepViT 1.3ms takes 1.3ms! Tsinghua's latest open source mobile neural network architecture RepViT Mar 11, 2024 pm 12:07 PM

Paper address: https://arxiv.org/abs/2307.09283 Code address: https://github.com/THU-MIG/RepViTRepViT performs well in the mobile ViT architecture and shows significant advantages. Next, we explore the contributions of this study. It is mentioned in the article that lightweight ViTs generally perform better than lightweight CNNs on visual tasks, mainly due to their multi-head self-attention module (MSHA) that allows the model to learn global representations. However, the architectural differences between lightweight ViTs and lightweight CNNs have not been fully studied. In this study, the authors integrated lightweight ViTs into the effective

How steep is the learning curve of golang framework architecture? How steep is the learning curve of golang framework architecture? Jun 05, 2024 pm 06:59 PM

The learning curve of the Go framework architecture depends on familiarity with the Go language and back-end development and the complexity of the chosen framework: a good understanding of the basics of the Go language. It helps to have backend development experience. Frameworks that differ in complexity lead to differences in learning curves.

Hand-tearing Llama3 layer 1: Implementing llama3 from scratch Hand-tearing Llama3 layer 1: Implementing llama3 from scratch Jun 01, 2024 pm 05:45 PM

1. Architecture of Llama3 In this series of articles, we implement llama3 from scratch. The overall architecture of Llama3: Picture the model parameters of Llama3: Let's take a look at the actual values ​​of these parameters in the Llama3 model. Picture [1] Context window (context-window) When instantiating the LlaMa class, the variable max_seq_len defines context-window. There are other parameters in the class, but this parameter is most directly related to the transformer model. The max_seq_len here is 8K. Picture [2] Vocabulary-size and AttentionL

In-depth understanding of the architecture and working principles of the Spring framework In-depth understanding of the architecture and working principles of the Spring framework Jan 24, 2024 am 09:41 AM

An in-depth analysis of the architecture and working principles of the Spring framework Introduction: Spring is one of the most popular open source frameworks in the Java ecosystem. It not only provides a powerful set of container management and dependency injection functions, but also provides many other functions, such as transactions. Management, AOP, data access, etc. This article will provide an in-depth analysis of the architecture and working principles of the Spring framework, and explain related concepts through specific code examples. 1. Core concepts of the Spring framework 1.1IoC (Inversion of Control) Core of Spring

Review! Comprehensively summarize the important role of basic models in promoting autonomous driving Review! Comprehensively summarize the important role of basic models in promoting autonomous driving Jun 11, 2024 pm 05:29 PM

Written above & the author’s personal understanding: Recently, with the development and breakthroughs of deep learning technology, large-scale foundation models (Foundation Models) have achieved significant results in the fields of natural language processing and computer vision. The application of basic models in autonomous driving also has great development prospects, which can improve the understanding and reasoning of scenarios. Through pre-training on rich language and visual data, the basic model can understand and interpret various elements in autonomous driving scenarios and perform reasoning, providing language and action commands for driving decision-making and planning. The base model can be data augmented with an understanding of the driving scenario to provide those rare feasible features in long-tail distributions that are unlikely to be encountered during routine driving and data collection.

Windows Server 2025 preview version welcomes update, Microsoft improves Insiders testing experience Windows Server 2025 preview version welcomes update, Microsoft improves Insiders testing experience Feb 19, 2024 pm 02:36 PM

On the occasion of releasing the build 26040 version of Windows Server, Microsoft announced the official name of the product: Windows Server 2025. Also launched is the Windows11WindowsInsiderCanaryChannel version build26040. Some friends may still remember that many years ago someone successfully converted Windows NT from workstation mode to server mode, showing the commonalities between various versions of Microsoft operating systems. Although there are clear differences between Microsoft's current version of the server operating system and Windows 11, those who pay attention to the details may be curious: why Windows Server updated the brand,

See all articles