开发者

Does database table namespacing exist?

开发者 https://www.devze.com 2023-01-06 05:31 出处:网络
I always wondered about one relevant (for me) but not existent feature of all the relational databases I worked with: the impossibility to namespace tables.

I always wondered about one relevant (for me) but not existent feature of all the relational databases I worked with: the impossibility to namespace tables.

in MySQL, for example, you can fully qualify the table with the database name, such as dbname.tablename, with the database acting as a "prefix" or "namespace". However, this feature stops here, and does not take you very far. Namespace support would grant you the possibility to have a syntax like dbname.namespace.table. You could group related tables into different namespaces, such as (fo开发者_如何学JAVAr a blog)

db.userdata.logininfo
db.userdata.preferences
db.postdata.content
db.postdata.acls

or

db.blog.whatever
db.wiki.whatever
db.common.auth

This would allow to stay within the same database (exploiting all the advantages of such setup) while at the same time granting a more flexible and self-documenting environment. Most of the time, however, I found that an underscore in the table name is used to serve this purpose as an apparent workaround.

My questions are : do DBMS with such feature exist (maybe with a different name)? is it deemed not important enough in database design practices to be granted support ?


I believe this is called a schema in SQL Server. It was introduced in SQL Server 2005. Tables belong to schemas, and are referred to via dot notation, such as owner.schema.tablename, for example dbo.HumanResources.Employee.

Here is one of many explanations of the schema in AdventureWorks, which is a commonly-used sample database for SQL Server.

Now that you know that that is the name SQL Server uses, you can find plenty of information about it. Here are a couple of articles providing some insight into the benefits of this feature:

Benefit from SQL Server 2005's new schema convention

Security Enhancements in SQL Server 2005: Schema


MS SQL Server (2005+) has schemas which you can interpret as namespaces (see AdventureWorks samples).

In Oracle tables are always owned by a user, but table access can be granted to other users, so you can achieve similar functionality.

You might also use quoted identifiers (MS [], Oracle "") to use "namespace.name" naming schemas.


I've never seen a hierarchical namespace on database tables, but you can use schemas in SQL Server 2005+ to do this. Similar constructs exist in other DBMS platforms as well.

Oracle has a module scope for stored procedure code (called packages) which gives you module level name spaces for code. Nothing equivalent exists in T-SQL, although stored procedures can live in schemas.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号