当涉及数据库列时,您是否喜欢详细命名? [英] Do you prefer verbose naming when it comes to database columns?

查看:76
本文介绍了当涉及数据库列时,您是否喜欢详细命名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您的偏好是哪一个?

假设我们有一个通用的Product表,其中有一个ID,一个名称和一个外部类别的引用。您是否喜欢为您的表命名:

Let's say we have a generic Product table that has an ID, a name, and a foreign key reference to a category. Would you prefer to name your table like:

CREATE TABLE Products
(
    ProductID int NOT NULL IDENTITY(1,1) PRIMARY KEY,
    CategoryID int NOT NULL FOREIGN KEY REFERENCES Categories(CategoryID),
    ProductName varchar(200) NOT NULL
)

使用列的显式命名(例如产品名称,产品 ID)如:

using explicit naming for the columns (e.g. ProductName, ProductID), or something like:

CREATE TABLE Products
(
    ID int NOT NULL IDENTITY(1,1) PRIMARY KEY,
    CategoryID int NOT NULL FOREIGN KEY REFERENCES Categories(ID),
    Name varchar(200) NOT NULL
)

从我所看到的,.NET世界中的惯例是明确的 - 样本倾向于使用第一个例子,而开源和RoR世界则倾向于第二。个人来说,我发现第一个更容易阅读和理解乍一看: select p.ProductID,p.ProductName,c.CategoryName from categories c inner join产品p on c.CategoryID = p.CategoryID 似乎比更自然,选择p.ID AS ProductID,p.Name AS ProductName,c.Name AS CategoryName从类别c inner join产品p on c.ID = p。 CategoryID

From what I've seen, the convention in the .NET world is to be explicit -- the samples tend to use the first example, while the open source and RoR world favor the second. Personally I find the first easier to read and comprehend at first glance: select p.ProductID, p.ProductName, c.CategoryName from Categories c inner join Products p on c.CategoryID = p.CategoryID seems a lot more natural to me than select p.ID AS ProductID, p.Name AS ProductName, c.Name AS CategoryName from Categories c inner join Products p on c.ID = p.CategoryID

我认为,给出基本的例子,我提供的并不重要,但是当你处理大量数据时,桌子?我仍然会发现第一个例子比第二个更好,尽管可能有两个组合可能值得研究(< Table> ID 的I​​D,但是只是名称的名称?)。显然,在现有的项目中,您应该遵循已经建立的惯例,但是对于新的发展呢?

I suppose that given the rudimentary example I provided it's not a big deal, but how about when you are dealing with lots of data and tables? I would still find the first example to be better than the second, although possibly some combination of the two might be worth looking into (<Table>ID for the ID, but just Name for the name?). Obviously on an existing project you should follow the conventions already established, but what about for new development?

您的偏好是什么?

推荐答案

表名已经给出上下文
不需要前缀列名。
加入表时使用table.column语法。

The table name already gives the context. No need to prefix columns name with it. When joining tables use table.column syntax.

这篇关于当涉及数据库列时,您是否喜欢详细命名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆