When I create a new table that need an ordering defined by the user, my first idea always go to a column name "order". Of course, this is NOT good since it's a reserved word.
当我创建一个需要用户定义排序的新表时,我的第一个想法总是指向一个列名“order”。当然,这并不好,因为它是一个保留词。
Which name are you giving to that column in your db models ?
您给db模型中的列取什么名字?
Thanks for your help.
谢谢你的帮助。
5 个解决方案
#1
41
I often use simple synonyms, "sort" for example.
我经常使用简单的同义词,例如“sort”。
#2
55
I use "position" in place of "order"
我用"position"代替"order"
#3
10
Just add the tick mark ` around the names of your tables and columns, for example:
只需在表和列的名称周围加上“勾号”,例如:
CREATE TABLE `order`
(
`order#` char(4) NOT NULL,
`ord_date` DATE,
Primary Key (`order#`)
)
ENGINE=InnoDB;
This allows for special characters and keywords to be used, at least this works for the current version of MySql.
这允许使用特殊的字符和关键字,至少这适用于当前版本的MySql。
#4
4
SQL Server, at least, allows you to use keywords if enclosed in square brackets, although I agree it's not a great idea.
至少,SQL Server允许您在方括号中使用关键字,尽管我同意这不是一个好主意。
I believe the last time I did this, I used SortOrder for the name. However, I often use prefixes that reflect the table such as UsrSortOrder so that's not always an issue.
我记得上次做这个的时候,我用了SortOrder这个名字。但是,我经常使用前缀来反映表,比如UsrSortOrder,所以这并不总是一个问题。
#5
3
In ANSI/ISO SQL, double quotes delimit keywords when used as column names; string literals are delimited by single quotes:
在ANSI/ISO SQL中,当作为列名使用时,双引号分隔关键字;字符串文字用单引号分隔:
select "from" = 'from' from foo
Microsoft SQL Server allows the use of square brackets in lieu of the double quotes as well:
Microsoft SQL Server也允许使用方括号来代替双引号:
select [from] = 'from' from foo
But either way, it makes a dreadful mess of your code (try reading the above to someone.)
但是无论哪种方式,它都会使您的代码变得非常糟糕(试试把上面的内容读给别人听)。
If I need an column for ordering results, I generally call it something like 'sequence_number' or 'sort_sequence'.
如果我需要一个列来排序结果,我通常把它称为'sequence_number'或'sort_sequence'。
#1
41
I often use simple synonyms, "sort" for example.
我经常使用简单的同义词,例如“sort”。
#2
55
I use "position" in place of "order"
我用"position"代替"order"
#3
10
Just add the tick mark ` around the names of your tables and columns, for example:
只需在表和列的名称周围加上“勾号”,例如:
CREATE TABLE `order`
(
`order#` char(4) NOT NULL,
`ord_date` DATE,
Primary Key (`order#`)
)
ENGINE=InnoDB;
This allows for special characters and keywords to be used, at least this works for the current version of MySql.
这允许使用特殊的字符和关键字,至少这适用于当前版本的MySql。
#4
4
SQL Server, at least, allows you to use keywords if enclosed in square brackets, although I agree it's not a great idea.
至少,SQL Server允许您在方括号中使用关键字,尽管我同意这不是一个好主意。
I believe the last time I did this, I used SortOrder for the name. However, I often use prefixes that reflect the table such as UsrSortOrder so that's not always an issue.
我记得上次做这个的时候,我用了SortOrder这个名字。但是,我经常使用前缀来反映表,比如UsrSortOrder,所以这并不总是一个问题。
#5
3
In ANSI/ISO SQL, double quotes delimit keywords when used as column names; string literals are delimited by single quotes:
在ANSI/ISO SQL中,当作为列名使用时,双引号分隔关键字;字符串文字用单引号分隔:
select "from" = 'from' from foo
Microsoft SQL Server allows the use of square brackets in lieu of the double quotes as well:
Microsoft SQL Server也允许使用方括号来代替双引号:
select [from] = 'from' from foo
But either way, it makes a dreadful mess of your code (try reading the above to someone.)
但是无论哪种方式,它都会使您的代码变得非常糟糕(试试把上面的内容读给别人听)。
If I need an column for ordering results, I generally call it something like 'sequence_number' or 'sort_sequence'.
如果我需要一个列来排序结果,我通常把它称为'sequence_number'或'sort_sequence'。