Is there any ISO standard of how to write SQL queries in DDL?

主宰稳场 提交于 2019-12-13 08:13:42

问题


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:


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.




回答2:


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
);


来源:https://stackoverflow.com/questions/1196034/is-there-any-iso-standard-of-how-to-write-sql-queries-in-ddl

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