tags:

views:

75

answers:

2

I am doing my first database project.

I would like to know which of the following ways should I use to make SQL queries in DDL.

#1

CREATE TABLE employees (   
    id            INTEGER   PRIMARY KEY,
    first_name    CHAR(50)  NULL,
    last_name     CHAR(75)  NOT NULL,
    dateofbirth   DATE      NULL
);

#2

CREATE TABLE employees (   
    id INTEGER PRIMARY KEY,
    first_name CHAR(50) NULL,
    last_name CHAR(75) NOT NULL,
    dateofbirth DATE NULL
);

#3

CREATE TABLE employees (   
    ID            integer   PRIMARY KEY,
    FIRST_NAME    char(50)  NULL,
    LAST_NAME     char(75)  NOT NULL,
    DATAOFBIRTH   data      NULL
);
+1  A: 

Sql coding Convections suggest :

CREATE TABLE employees
(   
id INTEGER PRIMARY KEY,
first_name CHAR(50) NULL,
last_name CHAR(75) NOT NULL,
dateofbirth DATE NULL
);
Adinochestva
+1  A: 

It doesn't really matter to the database, and so you should generally go for what's more readable and maintainable. There are a lot of different conventions out there, and I switch between them depending on circumstances all the time. Imo, what's good for a small query isn't the same as what's good for a more-complicated query.

In this case, I think your #3 looks most readable. But that's just my opinion and if there are conventions or existing expectations for how the code looks where you are, stick to that.

Joel Coehoorn