问题描述
我正在将我们从MSAccess后端过渡到SQL Server后端.
I am in the process of transitioning us from an MSAccess backend to a SQL Server back end.
在没有真正考虑关键字的情况下,我们的计划具有一个Admin,Order和Address模式.我一直阅读并获悉,您永远不要将关键字用作模式,函数,存储过程等名称,这样做确实会给您带来麻烦. .
Without really considering keywords our plan has an Admin, Order and Address schema.I have always read and been taught that you should never use keywords as schema, function,stored procedure, etc. names and that doing so will really hose you.
如果我打算始终明确地定义自己的架构(例如[Admin] .CompanyInformation)成为标准做法,那么使用关键字会引起问题吗?
If I plan to make it standard practice to always explicitely define my schema (E.G. [Admin].CompanyInformation) then is using a keyword an issue?
推荐答案
再一次,使用架构限定对象名称与使用保留字作为标识符无关.即使使用架构名称来限定字,您仍然会遇到使用保留字作为名称的问题.示例:
Once again, qualifying your object names with the schema is NOT related to the use of reserved words as identifiers. You will still encounter a problem using a reserved word as a name even if you qualify it with the schema name. Example:
set nocount on;
use tempdb;
go
create table dbo.[table] (id int not null);
print 'creating dbo.table as a table';
go
-- the next two statements fail
select * from table;
select * from dbo.table;
go
print '';
print 'select from dbo.[table] works**';
select * from dbo.[table];
if object_id('dbo.table') is not null
drop table dbo.[table];
go
所以-是的,您应该使用架构名称.是的-您应该避免使用保留字作为对象名称.前者并不能否定后者的需要.另外,您应该知道对象名称的其他规则-常规标识符的规则为 https://docs.microsoft.com/zh-cn/sql/relational-databases/databases/database-identifiers .
So - yes you should use the schema name. And yes - you should avoid the use of reserved words as object names. Doing the former does not negate the need to do the latter. And there are additional rules for object names that you should know - the rules for regular identifiers are https://docs.microsoft.com/en-us/sql/relational-databases/databases/database-identifiers.
即使您选择不遵循规则,您也可能会使用未开发且编写不当的软件-当遇到非常规标识符的对象名称时,该软件将无法正常工作. 那个原因是遵守常规标识符规则的最佳原因(其中之一是避免使用保留字作为名称).
And even if you choose to NOT follow the rules, you will probably use software that you did not develop and that was not written carefully - which will fail to work correctly when it encounters an object name that is not a regular identifier. And THAT reason is the best reason for adhering to the rules for regular identifiers (one of which is to avoid using reserved words as names).
这篇关于SQL Server和关键字架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!