1

I am creating a database with about 40 different tables.

I have heard about people grouping tables into database 'schemas' - what are the implications of using different schemas in a database? Can tables from one schema still relate to another schema? What are the functional differences between different schemas?

1

3 Answers 3

1

Where are schemas located in SSMS? They are rightfully placed under the security tab.

Lets use the AdventureWorks databases.

If you assign security at the schema level, purchasing users will only have access to the purchasing table and sales people will have only access to the sales tables.

In fact, they will not even see the other tables if you set it up correctly.

If you combine schemas with creating tables/indexes on file groups, now you can place all the sales people onto file group sales and purchasing on file group purchasing.

IE - Spreading the I/O load.

In short, I think schemas are an unknown and little used feature.

Check out my blog article on this fact.

http://craftydba.com/?p=4326

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

I assume that you are talking about SQL Server. You can join and reference between tables in different schemas. I see it mostly used for visual organization and/or for managing objects' permission (you can assign permissions at the schema-level).

If you are worried about any negative effects of doing dbo.table vs custom.table - there aren't any that I imagine you would encounter.

4 Comments

What do you mean by permissions? In terms of allowing different logins to access the data?
Also can a schema span across multiple databases? Somewhere I read that a schema is like a 'blueprint' but that doesn't mesh with what I am reading here..
Schemas have owners and you can grant/deny access to a schema vs just the database. Keep in mind that some RDBMS's use the term 'schema' as an equivalent to 'database' (i.e. MySQL). You can have multiple databases that have schemas with the same name; however, those schemas would have no real/physical relationship with each other.
It is used for security and management. Yes, you can have two tables with the same name in two schemas. For instance, [ACTIVE] and [STAGE]. It also adds more meaning to the table.
1

Schemas are just collections of database objects. They are useful for maintaining separation of sets of objects.

There is always at least one schema. For SQL Server it is named dbo.

One implication of having multiple schemas is that you will have to manage permissions for the various schemas. This is usually done via a role that's associated with the schema.

Objects in one schema are available to objects from another, and there is no performance penalty in writing queries that use objects from multiple schemas.

2 Comments

Are there any guidelines/best practices for how to use schemas?
Yes, Microsoft has a article on TechNet titled "SQL Server Best Practices - Implementation of Database Object Schemas" which can be found here: technet.microsoft.com/en-us/library/dd283095(v=sql.100).aspx

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.