Is there a "time" type that represents such that HH: mm in SQL?

5

I am a SQL beginner and I am creating a table, my doubt is that I have defined my start time and end time as VARCHAR2 to enter a time, which correspond to some classes (of a gym), that it would be more correct to create it with some type time , or with VARCHAR2 and enter start time and end time to each class manually with a INSERT INTO?

CREATE TABLE CLASES(
OID_CL SMALLINT,
nombre VARCHAR2(20),
horaInicio VARCHAR2(10),
horaFin VARCHAR2(10),
disponibilidadClase VARCHAR2(20),
codigo VARCHAR2(6),
PRIMARY KEY(OID_CL),
FOREIGN KEY(codigo) REFERENCES REGISTRO_CLASES
);
    
asked by RoyalUp 11.08.2016 в 12:34
source

2 answers

2

Theoretically, a data type time is more correct than a varchar2 because it will better represent the data internally in the database and will give you the flexibility to use some tools that may be convenient (such as functions to manipulate time such as DATEDIFF or DATEADD )

The question you must ask is "Why should I use those fields?". If you are going to use them to perform operations of hours and / or dates (calculate the time the class lasts or if there is conflict between classes), definitely use a time . If you are only going to use them to display them on the screen, it is really indifferent to the type of data you choose (although technically time would be the right thing to do, and surely a time will come when it will be more convenient for you).

    
answered by 11.08.2016 / 13:18
source
1

If you are going to use only hours, minutes, seconds and / or nanoseconds, use time , after all, although the difference is minimal, large-scale consultations will always be slower when you have data left over (the date in this case).

Take a look at the official documentation and you can see the differences. To start time it has more precision in nanoseconds than datetime. In turn, on the other hand, there is datetime2, which extends a normal datetime with the precision of a time in ns.

    
answered by 11.08.2016 в 13:27