有没有办法在 SQL Server 中不使用方括号? [英] Is there a way to not use square brackets in SQL Server?

查看:45
本文介绍了有没有办法在 SQL Server 中不使用方括号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Microsoft SQL Server 中,我有一个名为 [Key] 的表,但我讨厌每次都必须将它称为 [Key].

In Microsoft SQL Server, I had a table called [Key], but I hated having to address it as [Key] each time.

所以我将其重命名为 ki.好吧,至少方括号不见了.

So I renamed it to ki instead. Well, at least the square brackets are gone.

现在我想做的是:

CREATE SYNONYM Key FOR ki

但这没有用.我想我倒霉了.还有其他好点子吗?

But that didn't work. I guess I'm out of luck. Any other bright ideas?

我从来没有像人或地址或任何东西那样有复数名称的桌子.一直是person表或address表.

I've never had a table with a plural name like people or addresses or anything. It's always been the person table or the address table.

推荐答案

我知道很多人不喜欢这样,但我总是对 sql 中的所有内容使用前缀或后缀.
tbl 表示表,stp 表示过程,v 表示视图等'.
在列名中,表名本身就是前缀:person_id、person_fkvalue 等.

I know alot of people don't like this, but I always use prefixes or suffixes for everything in sql.
tbl for tables, stp for procedures, v for views etc'.
In column names the table name itself is the prefix: person_id, person_fkvalue etc'.

这样我就不用处理保留字了,马上就能知道这个列属于哪个表.
这也消除了在连接中为表名使用别名的需要.
我非常喜欢使用有意义的名称,因此即使是派生表也通常会使用名称而不是字母.

This way I never have to deal with reserved words, and can immediately know to what table the column belongs to.
This also eliminates the need of using aliases for table names in joins.
I'm a big fan of using meaningful names, so even derived tables usually gets a name and not a letter.

这篇关于有没有办法在 SQL Server 中不使用方括号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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