Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Data Management

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « Choosing operating modes for mirroring over a WANCalculating number of workdays between 2 dates »
    comments


    Chaos or order?

    Managing objects in large and small installations of SQL Server can be a job in itself at times. In particular, for the DBA, objects we create on the instances we manage more often than not are found littered over the user and system databases. These objects more often are found in the master database in SQL Server. Really, why not put them there? We are the “masters” over the database server right? SSMS has this quality to it that when we connect to it, we get the master database glaring us in the face by default just like a booby. So of course that means we create our objects there. Right?

    Who's really the booby?

    After years managing the databases, we may find ourselves feeling just like that booby when it takes minutes, hours and sometimes even failing to find the scripts we previously created to maintain our database servers.

    Maintaining order as a DBA starts with our own messes. That’s a pretty direct statement we can really dive into. SQL Server has for many versions given us the ability to manage our messes by grouping them into meaningful areas called schemas. Many times people set schemas aside and only think of them as a security method but they are much more. They take the booby out of us!

    In my own installations each instance contains a DBA database and everything I do as a DBA or Developer resides in there. To learn more about that first step in maintaining order check out, "Instance design; Where to do your work as a DBA and DB Developer".

    We can go much farther than that knowing schemas are available to us by grouping objects specific to other databases we maintain.


    Let’s say we have two databases on an instance named, ERP and WMS. In our DBA database we can create schemas to match the databases such as WMS_OBJ and ERP_OBJ. Now when we create procedures, function, views and so on we can put them into the schema that represents the database they refer to.

    1. CREATE PROCEDURE WMS_OBJ.GRABAWIDGET
    2. AS
    3. SELECT WIDGETS FROM WMS.WIDGET_TABLE

    Without much thought we can quickly find all our objects

    1. SELECT * FROM INFORMATION_SCHEMA.ROUTINES
    2. WHERE SPECIFIC_SCHEMA = 'WMS_OBJ'


    Quickly we see the grouping and maintenance benefits of doing this but it doesn’t stop there. Once these objects are grouped in schemas, we can manage all of them as a single entity. They can be scripted to DR sites quickly, replicated, moved and a really cool point, we can authorize users to gain access to these schemas. If new team members come into your group you can quickly give them the schema rights they need to get started while maintaining the other schemas and security levels. We can transfer objects from schema to schema as well making migrations quicker and easier.

    Take aways…

    In all, schemas make us better DBAs by allowing us quicker responses to situations by having order on our database servers. Security is stronger and better managed as well. Upon connecting to SSMS, first check to see if you are in the master database. Get in the habit of working outside the master database for greater control and to leave a smaller footprint on the system side of SQL Server. Take a few minutes to look at the objects used daily, monthly or even yearly and see if they can be grouped into schemas. After the initial work of creating the schemas and moving objects to them, I think order just may be achieved.

    About the Author

    Ted Krueger is a SQL Server MVP and has been working in development and database administration for 13+ years. Specialties range from High Availability and Disaster / Recovery setup and testing methods down to custom assembly development for SQL Server Reporting Services. Ted blogs and is also one of the founders of LessThanDot.com technology community. Some of the articles focused on are Backup / Recovery, Security, SSIS and working on SQL Server and using all of the SQL Server features available to create stable and scalable database services. @onpnt
    Social SitingsTwitterLinkedInLTD RSS Feed
    1328 views
    Instapaper

    3 comments

    Comment from: SQLDenis [Member] Email
    SQLDenis Schemas are an awesome tool to segregate objects into a logical group. Unfortunately I still see a lot of 2005 and 2008 instance where the only schema is dbo (and sys of course)
    02/26/10 @ 08:37
    Comment from: Christiaan Baes (chrissie1) [Member]
    Christiaan Baes (chrissie1) I like the selfportrait.
    02/26/10 @ 11:32
    Comment from: Ted Krueger (onpnt) [Member]
    Ted Krueger (onpnt) Only if I looked that good ;-)
    02/26/10 @ 14:27

    Leave a comment


    Your email address will not be revealed on this site.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)