Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2010
    Location
    Orlando, FL
    Posts
    311
    Provided Answers: 1

    Question Unanswered: Capitalize Data Types?

    I know it's common procedure when typing / documenting ANSI SQL to capitalize statements like 'SELECT', 'INSERT', 'DROP', 'UPDATE', & 'LIKE', however my question is what about data types? Is it recommended to capitalize data types in my code or leave them lowercase?

    Code:
    CREATE TABLE employees
    (
    emp_id integer PRIMARY KEY NOT NULL,
    fname varchar(20) NOT NULL,
    lname varchar(20) NOT NULL,
    email varchar(50) UNIQUE NOT NULL,
    dob date NOT NULL,
    salary decimal(19,4) NULL,
    city varchar(40) NOT NULL,
    state char(2) NOT NULL
    );

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Do whatever you prefer, but be consistent - and document it.

    Style depends a lot on the DBMS as well. In the PostgreSQL world, people tend to write everything in lowercase. In the Oracle world, people tend to write everything in uppercase and in the Microsoft world peopel tend to use CamelCase.

  3. #3
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Why do you worry to capitalize datatypes?
    You also capitalized other keywords than statements, like 'TABLE', 'PRIMARY KEY', 'UNIQUE', 'NOT NULL', 'NULL'.

    I prefer to capitalize keywords used to construct SQL statements(including built-in functions, attributes, options, so on),
    and use all lowercases for others(user supplied resource names including user-defined-functions), even if that were compound words.

    And, I prefer to use under score to separate each words in a compound word.
    For example, I prefer to use employee_id than EmployeeId or EmployeeID.
    Because, all of employee_id, Employee_Id, Employee_ID, EMPLOYEE_ID would be treated as same thing in SQL.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Quote Originally Posted by tonkuma View Post
    Because, all of employee_id, Employee_Id, Employee_ID, EMPLOYEE_ID would be treated as same thing in SQL.
    Not necessarily with MySQL or SQL Server. They can be case sensitive even without using double quotes.

  5. #5
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    Quote Originally Posted by shammat View Post
    Not necessarily with MySQL or SQL Server. They can be case sensitive even without using double quotes.
    I think that I see the reason of you worte "Style depends a lot on the DBMS as well".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •