Thursday 26 December 2013

SQL datatypes

Data Types:-
  Data types are a classification of a particular type of information. It is easy for humans to distinguish between different types of data. SQL supports following data types:

1)Character(n)
     This data type represents a fixed length string of exactly 'n' characters where 'n'is greater than zero and should be an integer.

Example:-
    Name character(10)
            or
    Name char(10)

2) Varchar(n) or character varying(n)
    This data type represents a varying length string whose maximum length is 'n' characters.

  Example:-
      Name varchar(n)

3) Numeric (p,q)
     This data type represent a decimal number 'p' digits and sign with assumed decimal point 'q' digits from the sign. Both 'p' and 'q' are integers.

  Example:-
    Price numeric(6,2)

4)Integer
    An integer represents a signed integer decimal or binary.

    Example:-
       Roll_No integer(3)

5) Small int
    A small integer is a machine independent subset of the integer domain type

  Example:-
   Roll_No small int(3)

6) Real, double precision
  Floating point and double-precision floating point numbers with machine dependent precision.

7) Float(n)
   A floating point number, with precision of at least n digits.

   Example:-
     Rate float(5,2)

8) Date
   A calendar date containing a (four-digit) year, month and day of the month

 Example:-
     Date_of_birth date



9) Time
   The time of day, in hours, minutes and seconds. A variant, time(p) can be used to specify the number of fractional digits for seconds (the default being 0)

 Example:-
  Arrival_time time

10) Time stamp
    A combination of date and time. A variant, timestamp (P), can be used to specify the number of fractional digits for seconds.

   Date and time values can be specified like this:
      date '2005-04-25'
      time '09:10:25'
      time stamp '2005-04-25 08:25:30.45'


  Dates must be specified in the format-year followed by month followed by day, as shown. The seconds field of time or timestamp can have a fractional part, as in the timestamp above

No comments:

Post a Comment