What good are SQL Server schemas?

后端 未结 12 1879
青春惊慌失措
青春惊慌失措 2020-11-27 10:43

I\'m no beginner to using SQL databases, and in particular SQL Server. However, I\'ve been primarily a SQL 2000 guy and I\'ve always been confused by schemas in 2005+. Yes

相关标签:
12条回答
  • 2020-11-27 10:53

    I know it's an old thread, but I just looked into schemas myself and think the following could be another good candidate for schema usage:

    In a Datawarehouse, with data coming from different sources, you can use a different schema for each source, and then e.g. control access based on the schemas. Also avoids the possible naming collisions between the various source, as another poster replied above.

    0 讨论(0)
  • 2020-11-27 10:54

    I think schemas are like a lot of new features (whether to SQL Server or any other software tool). You need to carefully evaluate whether the benefit of adding it to your development kit offsets the loss of simplicity in design and implementation.

    It looks to me like schemas are roughly equivalent to optional namespaces. If you're in a situation where object names are colliding and the granularity of permissions is not fine enough, here's a tool. (I'd be inclined to say there might be design issues that should be dealt with at a more fundamental level first.)

    The problem can be that, if it's there, some developers will start casually using it for short-term benefit; and once it's in there it can become kudzu.

    0 讨论(0)
  • 2020-11-27 10:55

    I tend to agree with Brent on this one... see this discussion here. http://www.brentozar.com/archive/2010/05/why-use-schemas/

    In short... schemas aren't terribly useful except for very specific use cases. Makes things messy. Do not use them if you can help it. And try to obey the K(eep) I(t) S(imple) S(tupid) rule.

    0 讨论(0)
  • 2020-11-27 10:57

    If you keep your schema discrete then you can scale an application by deploying a given schema to a new DB server. (This assumes you have an application or system which is big enough to have distinct functionality).

    An example, consider a system that performs logging. All logging tables and SPs are in the [logging] schema. Logging is a good example because it is rare (if ever) that other functionality in the system would overlap (that is join to) objects in the logging schema.

    A hint for using this technique -- have a different connection string for each schema in your application / system. Then you deploy the schema elements to a new server and change your connection string when you need to scale.

    0 讨论(0)
  • 2020-11-27 11:01

    They can also provide a kind of naming collision protection for plugin data. For example, the new Change Data Capture feature in SQL Server 2008 puts the tables it uses in a separate cdc schema. This way, they don't have to worry about a naming conflict between a CDC table and a real table used in the database, and for that matter can deliberately shadow the names of the real tables.

    0 讨论(0)
  • 2020-11-27 11:02

    Schemas logically group tables, procedures, views together. All employee-related objects in the employee schema, etc.

    You can also give permissions to just one schema, so that users can only see the schema they have access to and nothing else.

    0 讨论(0)
提交回复
热议问题