Microsoft SQL Server accept blank in name of variables - Why?

萝らか妹 提交于 2019-12-08 05:02:56

问题


Microsoft SQL Server accept blank space in name of variables by usage of brackets:

CREATE TABLE [dbo].[MyDataTable](
    [Compo 1] [nvarchar](50) NULL,
    [Compo 2] [nvarchar](50) NULL,
    [Compo 3] [nvarchar](50) NULL,
    compo1 [nvarchar](50) NULL,
    compo2 [nvarchar](50) NULL,
    compo3 [nvarchar](50) NULL,
    compo_1 [nvarchar](50) NULL,
    compo_2 [nvarchar](50) NULL,
    compo_3 [nvarchar](50) NULL)

Problem is what happens when a tool like entity framework or NHibernate or any other ORM tool or even manually I try to create a model based on my database?

When using C#, VB.NET, Java and probably most development language it is never possible to use white space in your variable name.

So, to fix this LINQPad default provider ignore and remove white space when generating C#, Linq2Db alternate provider seems to replace blanks by underscore. All these generation rules can conflict with other variable in my database in case I have a variable that already is the alternative solution like in my example.

In LINQPad I have this

MyDataTable.Compo1; // With capital letter and mapto [Compo 1] [nvarchar](50) NULL,
MyDataTable.compo2; // with small letter and map to compo2 [nvarchar](50) NULL,
MyDataTable.compo3;
MyDataTable.compo_1;
MyDataTable.compo_2;
MyDataTable.compo_3;

So, my questions: how is it possible that Microsoft accepted this as SQL valid column name? Is it part of SQL standard or specific to SQL Server? What can be a correct positive use cas of using blank in my column names?

来源:https://stackoverflow.com/questions/55295594/microsoft-sql-server-accept-blank-in-name-of-variables-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!