Data Types

Getting numbers in specific precision and scale.
DECIMAL and NUMERIC are functionally same.
Syntax:
DECIMAL (precision [ , scale ] )
NUMERIC (precision [ , scale ] )
Example:
SELECT CAST (123 AS DECIMAL (5,2) ) --returns 123.00
SELECT CAST (12345 AS DECIMAL (10,5) ) --returns 12345.12000
Approximation of numbers in data types.
SELECT CAST (PI() AS FLOAT) ----returns 3.14159265358979
SELECT CAST (PI() AS REAL) ----returns 3.141593
Data types that use exact numbers, divided between ranges and storage sizes.

Data types that represent money and currency

Binary data types that have either fixed or variable lengths.
Syntax:
BINARY [ ( n_bytes ) ]
VARBINARY [ ( n_bytes | max ) ]
n_bytes can differ from 1 to 8000 bytes. max indicates that the maximum storage space is 2^31-1.
Examples:
SELECT CAST (12345 AS BINARY (10) ) --0x000000000000000003039
SELECT CAST (12345 AS VERBINARY (10)) --0x00003039
String data types that have either fixed or variable lengths.
Syntax:
CHAR [ ( n_bytes ) ]
VERCHAR [ ( n_bytes ) ]
Examples:
SELECT CAST ('ABC' AS CHAR (10) ) ---'ABC '(padded with spaces on the right)
SELECT CAST ('ABC' AS VARCHAR (10) ) ---'ABC' (no padding due to variable caracter)
SELECT CAST ('ABCDEFGHIJKLMNOPRSTUVWYZ' AS CHAR (10)) ---'ABCDEFGHIJ' (truncated to 10 caracters)
UNICODE String data types that have either fixed or variable lengths.
Syntax:
NCHAR ( (n_bytes) ]
NVARCHAR [ ( n_bytes| max) ]
You can use MAX for very long strings longer than 8000 characters.
A 16-byte GUID / UUID.
DECLARE @GUID UNIQUEIDENTIFIER =NEWID ();
SELECT @GUID ---'E28B3BD9-9174-41A9-8508-899A78A33540'
DECLARE @bad_GUID_string VARCHAR(100) ='E28B3BD9-9174-41A9-8508-899A78A33540_foobarbaz'
SELECT
@bad_GUID_string, --'E28B3BD9-9174-41A9-8508-899A78A33540'
CONVERT (UNIQUEIDENTIFIER, @bad_GUID_string) --'E28B3BD9-9174-41A9-8508-899A78A33540'
- Date; only contains the date data value.
- Date time; contains the time value in addition to the date. DatetimeOffset contains the Timezone.
- Int32; allows keeping integers.
- Double; holds numbers up to 2 fractions.
- Decimal; allows keeping numbers up to 10 fractions.
- FileContent; is used to store files such as PDFs.
- Guid; indicates a singular value, such as an ID number. In the managedDB database, which is associated with a workspace specific to Kuika, an ID of GUID type is assigned to each record.

- Image; is used to store image files.
- Location; is used to hold geographic coordinates and GPS data.
- Signature; keeps the signature in image format.

- String; stores alphanumeric characters.
- AutoIncrement; is an auto-incrementing value type.
Last modified 1d ago