질의작성

INSERT수행 시, 현재날짜,현재시각으로 자동 입력하는 방법

by 주현 posted Jul 08, 2015


CUBRID에서 지원하는 날짜/시간 데이터 타입입니다.

 


데이터 입력 시, 기본값으로 현재날짜 혹은 현재 시각을 입력할 수 있는 방법입니다.

아래 예제와 같이 default를 사용하시면 됩니다.


참고)

CURDATE(), CURRENT_DATE(), CURRENT_DATE, SYS_DATE, SYSDATE는 모두 동일하며현재 날짜를 DATE타입(MMDDYYYY)로 반환합니다.

CURRENT_DATETIME, CURRENT_DATETIME(), NOW(), SYS_DATETIME, SYSDATETIME는 동일하며현재 날짜를 DATETIME타입으로 반환합니다산술 연산의 단위는 milli-sec입니다.




타입

bytes

최소값

최대값

비고

DATE

4

0001 1 1

9999 12 31

예외적으로 DATE '0000-00-00' 입력할 있다.

TIME

4

00 00 00

23 59 59

 

TIMESTAMP

4

1970 1 1 0 0 1(GMT) 1970 1 1 9 0 1(KST)

2038 1 19 3 14 7(GMT) 2038 1 19 12 14 7(KST)

예외적으로 TIMESTAMP '0000-00-00 00:00:00' 입력할 있다.

DATETIME

8

0001 1 1 0 0 0.000

9999 12 31 23 59 59.999

예외적으로 DATETIME '0000-00-00 00:00:00' 입력할 있다.

csql> create table test(a int, b DATE default SYSDATE, d TIMESTAMP default SYSDATE, e DATETIME default SYSDATE); Execute OK. (0.002299 sec) Committed.

 

1 command(s) successfully processed.

csql> insert into test (a) values(1);

1 row affected. (0.001165 sec) Committed.

1 command(s) successfully processed.

csql> select * from test;

=== <Result of SELECT Command in Line 1> ===

            a  b           d                          e

===================================================================================

            1  07/08/2015  12:00:00 AM 07/08/2015     12:00:00.000 AM 07/08/2015

1 rows selected. (0.009081 sec) Committed.

1 command(s) successfully processed.

 

 

csql> create table test1(a int, b TIMESTAMP default SYSDATETIME, c DATETIME default SYSDATETIME);

Execute OK. (0.002243 sec) Committed.

1 command(s) successfully processed.

 

csql> insert into test1(a) values(1);

1 row affected. (0.001221 sec) Committed.

1 command(s) successfully processed.

csql> select * from test1;

=== <Result of SELECT Command in Line 1> ===

            a  b                          c

=======================================================================

            1  10:17:14 AM 07/08/2015     10:17:14.545 AM 07/08/2015

1 rows selected. (0.008762 sec) Committed.

1 command(s) successfully processed.


csql> insert into test1(a) values(2);

1 row affected. (0.001049 sec) Committed.

1 command(s) successfully processed.


csql> select * from test1;

=== <Result of SELECT Command in Line 1> ===

            a  b                          c

=======================================================================

            1  10:17:14 AM 07/08/2015     10:17:14.545 AM 07/08/2015

            2  10:23:37 AM 07/08/2015     10:23:37.828 AM 07/08/2015

2 rows selected. (0.008829 sec) Committed.


Articles

1 2 3 4 5 6 7 8 9 10