Domain Types in SQL – Structured Query Language

A user-defined data types in SQL are Domain Type. You can use the domain instead of a built-in SQL data type. To know the difference between user-defined and built-in data types check our post.  You can use the domain instead of a built-in SQL data type when declaring a column. That column will then be restricted only to use the same domain. Some good definitions of Domain type in SQL are found HERE.

Domain Types in SQL

INT:

Representing Numbers in SQL table.
There are Finite integers and it varies from machine to machine. The Size will contain in the database is also machine-dependent.

NUMERIC(P,D):

It’s just like a function where the first parameter P defines thenumber left to the decimal point and the second Parameter D defines the number right to the decimal point. Let’s say we have defined a table column with storing NUMERIC(2,2). We gave the number 24.65 to store It will store it correctly, But if we provide a number 233.4 or 2.343 then It will not be stored correctly.

Fl0AT(N):

It is just like numeric but here the parameter is only the precision to the right. For Example, if the FLOAT(2) is defined for a column and we store a 2.42 it will be stored correctly but it will not store 3.433.

CHAR(N):

User-specified length n for a fixed-length character string. For example, we defined CHAR(3) to store values in a column, The value “AHE” will be stored correctly but it will not store “AH” or “AHEE”.

VARCHAR(N):

It is the same as the CHAR(N) with only defining the maximum length, not the fixed length. For example, if we define VARCHAR(3) we can store strings up to the length of 3 like “AAA”, “A”, “AA”, etc but can’t store “AAAA” because it will exceed the maximum length.

DOUBLE PRECISION:

All the Floating numbers are included here with machine-dependent Precision.

SMALLINT:

a subset of the integer domain type that is machine-dependent


Posted

in

by

Tags: