Click here to monitor SSC

John Magnabosco

SQL Server Development and Data Security

Shades of Schemas

Published Saturday, November 21, 2009 11:22 AM

I am sure that some of the database nomenclature that is used might be a bit confusing to those who are entering into the wonderful world of SQL Server. An example would be the varying use of the word "schema".

In a general database terms a schema is the organization and definition of the tables within a database, their relationship to one another and the columns that are contained within them. In layman's terms: it is the design of the database.

In SQL Server 2000, the term "schema" was directly associated with ownership of database objects (tables, views, stored procedures, etc.), which is a slight deviation from the aforementioned definition. The ownership of database objects is important because the object owner (user or role) is implicitly granted all privileges to the object. If the ownership is not explicitly defined when the object is created, the default owner is the same as the database owner; which is defined by the "dbo" default schema.

In many ways, the difference between users and ownership schemas were synonymous in SQL Server 2000. With the release of SQL Server 2005, the database object schema provided a new definition of a "schema". In this case a schema is a physical database object which serves as a logical grouping of database objects. For the .NET Developer, it is very similar to the concept of namespaces. While the ownership aspect still remains it has been separated from the principal in a such a way that it is much more flexible and scalable.

Database object schemas are a great addition to SQL Server and in many ways is more consistent with the original definition of a schema than it's SQL Server 2000 counterpart.

by Johnm

Comments

 

timothyawiseman@gmail.com said:

I am a great fan of using SQL Server 2005's grouping of schemas as a way to logical group objects and they can vastly simplify assignment of permissions.  

I think it would have been more convenient if they had found a different word that though.  Having schema both mean structure and a logical box to put other objects in can be confusing at times.
December 4, 2009 11:38 AM
 

BillTalada said:

If schema now means database folder, then we'll have to use something like layout to refer to our tables and foreign keys.

I'm trying to think how I can use schemas in an existing OLTP database.  I'm not coming up with any advantages to it.  In fact, I see it would take a large amount of editing to retro-fit schemas with no real benefit.  Afterwards, programmers would have to do a lot more typing to accomplish what they used to do.

Maybe in new development where there will be over several hundred tables in the database it would make sense.  Am I missing anything?
December 4, 2009 3:13 PM
 

Johnm said:

An example where database object schemas has proven to be very beneficial is in a project that I am currently working on. I have tables that contain sensitive identification data, such as social security numbers and driver's license numbers. I store these in a table that is contained within a SensitiveInformation database object schema.

As additional sensitive data is added to the database, such as financial accounts, the tables involved can be tucked away in the SensitiveInformation database object schema. I then can control permissions to the whole grouping rather than each individual tables.

In my book "Protecting SQL Server Data" I mention how database object schemas can be a powerful way to isolate and segregate sensitive data from non-sensitive data.

There are many more examples of where database object schemas can be beneficial; but in the context of my typical blogging subjects this is one good example of how they can be used.
December 4, 2009 5:58 PM
 

Atif Shehzad said:

Due to changed concept of schema in SQL Server 2005 objects are no more dependent on existence of their owner now.
December 31, 2009 1:49 AM
You need to sign in to comment on this blog

About Johnm

John Magnabosco manages the Data Services Group at one of the fastest growing companies in the United States. He is also a Co-Founder of the Indianapolis Professional Association for SQL Server (IndyPASS), Co-Founder of IndyTechFest, the author of the book titled "Protecting SQL Server Data" and contributing author of "SQL Server MVP Deep Dives Volume 2".
<November 2009>
SuMoTuWeThFrSa
25262728293031
1234567
891011121314
15161718192021
22232425262728
293012345
How to Kill a Company in One Step or Save it in Three
 The majority of companies that suffer a major data loss subsequently go out of business. David Wesley... Read more...

Migrating from OCS 2007 R2 to Lync: Part 4
 Having migrated the rest of our users and legacy resources across, and start getting ready to... Read more...

Automated Script-generation with Powershell and SMO
 In the first of a series of articles on automating the process of building, modifying and copying SQL... Read more...

Seth Godin: Big in the IT Business
 Seth Godin has transformed our understanding of marketing in IT. He invented the concept of 'permission... Read more...

Using SQL Test Database Unit Testing with TeamCity Continuous Integration
 With database applications, the process of test and integration can be frustratingly slow because so... Read more...