locked
Quick column naming question RRS feed

  • Question

  • I'm working on a project where one of the columns in one of the tables is called "Datetime".  When I'm writing a SPROC using this column it is displayed in blue because the SPROC designer thinks it's a type.

    Is there any reason not to use "Datetime" as a column name?

    Thanks

    Edward

    Friday, December 10, 2010 3:57 PM

Answers

  • Datetime is a reserved keyword in SQL Server (it's a basic type). It is always a good idea to stay away from the reserved keywords when naming columns, tables, etc.

    So, if there is an opportunity to use a better name for that column, go for it.


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    Friday, December 10, 2010 4:11 PM
    Answerer
  • Using reserved words is usually not a good  idea with database names or in programming. I like to use a naming convention that has a name or descriptor and a classword at the end of all column names. The classword decribes the datatype or use. Since Datetime is a common classword the column should have a name like, UpdateDateTime or TransactionDateTime. I usually abbreviate the classword. DateTime = DT, Code = CD, Count = CNT, Percent = PCT etc...
    Monday, December 13, 2010 1:57 AM

All replies

  • Datetime is a reserved keyword in SQL Server (it's a basic type). It is always a good idea to stay away from the reserved keywords when naming columns, tables, etc.

    So, if there is an opportunity to use a better name for that column, go for it.


    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    Friday, December 10, 2010 4:11 PM
    Answerer
  • Edward

    In addtion to Naom's answer  as alternative you can name as Date_Time ...

    Actually it depends on what  you are going to store there.. If  you want to store the date of user's changing it could date_modified , or date_created  and etc...


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    Sunday, December 12, 2010 9:06 AM
  • Using reserved words is usually not a good  idea with database names or in programming. I like to use a naming convention that has a name or descriptor and a classword at the end of all column names. The classword decribes the datatype or use. Since Datetime is a common classword the column should have a name like, UpdateDateTime or TransactionDateTime. I usually abbreviate the classword. DateTime = DT, Code = CD, Count = CNT, Percent = PCT etc...
    Monday, December 13, 2010 1:57 AM
  • hello edward

    Datetime is a data type as it integer and varchar are , which makes it not to used but I think you can use table_name.[column_name] so that you can avoid the restrication . I hope it will work fine.

    vote If it solves your problem.

    Monday, December 13, 2010 6:42 AM