Friday, December 11, 2009

Data Types in SQL

Data Types :


Datetime Data Types :

  • The TIMESTAMP data type is an extension of the DATE data type.
  • It stores the year, month, and day of the DATE data type plus hour, minute, and second values as well as the fractional second value.
  • You can optionally specify the time zone.
  • TIMESTAMP[(fractional_seconds_precision)]
  • TIMESTAMP[(fractional_seconds_precision)] WITH TIME ZONE

DEFAULT Option in SQL

DEFAULT Option :
  • Specify a default value for a column during an insert.
  • ... hire_date DATE DEFAULT CURRENT_DATE, ...
  • Literal values, expressions, or SQL functions are legal values.
  • Another column’s name or a pseudo column are illegal values.
  • The default data type must match the column data type.
  • CREATE TABLE hire_dates (id numeric(8), hire_date DATE DEFAULT CURRENT_DATE);
Create the table :
  • CREATE TABLE dept_info (deptno numeric(2), dname varchar(14), loc varchar(13), create_date DATE DEFAULT CURRENT_DATE);
Confirm table creation :
  • \d dept_info

Followers