{"id":447,"date":"2010-07-27T22:33:56","date_gmt":"2010-07-28T03:33:56","guid":{"rendered":"http:\/\/www.dpriver.com\/blog\/?page_id=447"},"modified":"2010-08-04T22:01:53","modified_gmt":"2010-08-05T03:01:53","slug":"sql-server-datatypes","status":"publish","type":"page","link":"https:\/\/www.dpriver.com\/blog\/list-of-demos-illustrate-how-to-use-general-sql-parser\/translate-sql-query-between-different-databases\/sql-server-datatypes\/","title":{"rendered":"SQL Server datatypes"},"content":{"rendered":"

\nDatatype conversion is one of the key issues when convert one dialect of SQL to another<\/a>. This article documents SQL Server datatypes and how to convert it to corresponding datatype of other databases.\n<\/p>\n

\nSQL Server supplies a set of system data types that define all the types of data that can be used with SQL Server. You can also define your own data types in Transact-SQL. Data types in SQL Server are organized into the following categories: Character strings, Unicode character strings, Binary strings, Exact numerics, Approximate numerics, Date and time, Other data types.\n<\/p>\n

### Character strings<\/span><\/h3>\n

\n
- char[(n)]\n
  \n
  - Description:<\/b> Fixed-length, non-Unicode character data with a length of n bytes<\/span>. n must be a value from 1 through 8,000. <\/li>\n
  - ISO synonym:<\/b> character<\/li>\n
  - Oracle:<\/b> char[(size)], 1 <= size <= 2,000 bytes<\/li>\n<\/ul>\n<\/li>\n
  - varchar [ ( n | max ) ]\n
    \n
    - Description:<\/b> Variable-length, non-Unicode character data. n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes<\/span>. <\/li>\n
    - ISO synonym:<\/b> character varying, char varying<\/li>\n
    - Oracle:<\/b> varchar2(n), or clob (n>4000)<\/li>\n<\/ul>\n<\/li>\n
    - text\n
      \n
      - Description:<\/b> Variable-length non-Unicode data in the code page of the server and with a maximum length of 2^31-1 (2,147,483,647) characters. When the server code page uses double-byte characters, the storage is still 2,147,483,647 bytes. Depending on the character string, the storage size may be less than 2,147,483,647 bytes.
        \nWill be removed in a future version of Microsoft SQL Server, use varchar(max) instead.<\/span> <\/li>\n
      - ISO synonym:<\/b> N\/A<\/li>\n
      - Oracle:<\/b> clob<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n

        ### Unicode Character strings<\/span><\/h3>\n
        \n
        - nchar[(n)]\n
          \n
          - Description:<\/b> Fixed-length Unicode character data of n characters<\/span>. n must be a value from 1 through 4,000. The storage size is two times n bytes.<\/li>\n
          - ISO synonym:<\/b> national char, national character<\/li>\n
          - Oracle:<\/b> nchar[(n)], 1 <= n <= 2,000 characters; nclob, n > 2000<\/li>\n<\/ul>\n<\/li>\n
          - nvarchar [ ( n | max ) ]\n
            \n
            - Description:<\/b>Variable-length Unicode character data. n can be a value from 1 through 4,000 characters<\/span>. max indicates that the maximum storage size is 2^31-1 bytes. The storage size, in bytes, is two times the number of characters entered + 2 bytes. <\/li>\n
            - ISO synonym:<\/b> national character varying, national char varying<\/li>\n
            - Oracle:<\/b> varchar2(n), or clob (n>4000)<\/li>\n<\/ul>\n<\/li>\n
            - ntext\n
              \n
              - Description:<\/b> Variable-length Unicode data with a maximum length of 2^30 – 1 (1,073,741,823) characters<\/span>. Storage size, in bytes, is two times the number of characters entered.
                \nWill be removed in a future version of Microsoft SQL Server, use nvarchar(max) instead.<\/span> <\/li>\n
              - ISO synonym:<\/b> national text<\/li>\n
              - Oracle:<\/b> nclob<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n

                ### Binary strings<\/span><\/h3>\n
                \n
                - binary [ ( n ) ]\n
                  \n
                  - Description:<\/b> Fixed-length binary data with a length of n bytes<\/span>, where n is a value from 1 through 8,000. The storage size is n bytes.<\/li>\n
                  - ISO synonym:<\/b> N\/A<\/li>\n
                  - Oracle:<\/b>raw(1)(n was omitted); raw(n), 1<=n<=2000;blob(n>2000)<\/li>\n<\/ul>\n<\/li>\n
                  - varbinary [ ( n | max) ]\n
                    \n
                    - Description:<\/b>Variable-length binary data. n can be a value from 1 through 8,000 bytes<\/span>. max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes.<\/li>\n
                    - ISO synonym:<\/b>binary varying<\/li>\n
                    - Oracle:<\/b> raw(1)(n was omitted); raw(n), 1<=n<=2000;blob(n>2000)<\/li>\n<\/ul>\n<\/li>\n
                    - image\n
                      \n
                      - Description:<\/b> Variable-length binary data from 0 through 2^31-1 (2,147,483,647) bytes<\/span>.
                        \nWill be removed in a future version of Microsoft SQL Server, use varbinary(max) instead.<\/span> <\/li>\n
                      - ISO synonym:<\/b> N\/A<\/li>\n
                      - Oracle:<\/b> blob<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n

                        ### Numerics<\/span><\/h3>\n
                        \n
                        - bigint\n
                          \n
                          - Description:<\/b> 8 bytes, The bigint data type is intended for use when integer values might exceed the range that is supported by the int data type.\n <\/li>\n
                          - ISO synonym:<\/b> N\/A<\/li>\n
                          - Oracle:<\/b>NUMBER(19)<\/li>\n<\/ul>\n<\/li>\n
                          - int\n
                            \n
                            - Description:<\/b> 4 bytes, The int data type is the primary integer data type in SQL Server.\n <\/li>\n
                            - ISO synonym:<\/b> N\/A<\/li>\n
                            - Oracle:<\/b>NUMBER(10)<\/li>\n<\/ul>\n<\/li>\n
                            - smallint\n
                              \n
                              - Description:<\/b> 2 bytes\n <\/li>\n
                              - ISO synonym:<\/b> N\/A<\/li>\n
                              - Oracle:<\/b> \tNUMBER(5)<\/li>\n<\/ul>\n<\/li>\n
                              - tinyint\n
                                \n
                                - Description:<\/b> 1 byte\n <\/li>\n
                                - ISO synonym:<\/b> N\/A<\/li>\n
                                - Oracle:<\/b>\tNUMBER(3)<\/li>\n<\/ul>\n<\/li>\n
                                - bit\n
                                  \n
                                  - Description:<\/b> An integer data type that can take a value of 1, 0, or NULL.\n <\/li>\n
                                  - ISO synonym:<\/b> N\/A<\/li>\n
                                  - Oracle:<\/b>\tNUMBER(3)<\/li>\n<\/ul>\n<\/li>\n
                                  - numeric[(p[,s])], decimal[(p[,s])]\n
                                    \n
                                    - Description:<\/b> Numeric data types that have fixed precision and scale.\n <\/li>\n
                                    - ISO synonym:<\/b> dec(p, s)<\/li>\n
                                    - Oracle:<\/b>number[(p[,s])]<\/li>\n<\/ul>\n<\/li>\n
                                    - money\n
                                      \n
                                      - Description:<\/b>Data types that represent monetary or currency values. The money and smallmoney data types are accurate to a ten-thousandth of the monetary units that they represent.\n <\/li>\n
                                      - ISO synonym:<\/b> N\/A<\/li>\n
                                      - Oracle:<\/b>number(19,4)<\/li>\n<\/ul>\n<\/li>\n
                                      - smallmoney\n
                                        \n
                                        - Description:<\/b>Data types that represent monetary or currency values. The money and smallmoney data types are accurate to a ten-thousandth of the monetary units that they represent.\n <\/li>\n
                                        - ISO synonym:<\/b> N\/A<\/li>\n
                                        - Oracle:<\/b>number(10,4)<\/li>\n<\/ul>\n<\/li>\n
                                        - float[(n)]\n
                                          \n
                                          - Description:<\/b>Approximate-number data types for use with floating point numeric data. Floating point data is approximate; therefore, not all values in the data type range can be represented exactly.\n <\/li>\n
                                          - ISO synonym:<\/b> float[(n)], for n = 8-15<\/li>\n
                                          - Oracle:<\/b>float(49)<\/li>\n<\/ul>\n<\/li>\n
                                          - real\n
                                            \n
                                            - Description:<\/b>\n <\/li>\n
                                            - ISO synonym:<\/b> float[(n)], for n = 1-7 <\/li>\n
                                            - Oracle:<\/b>float(23)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n

                                              ### Date and Time<\/span><\/h3>\n
                                              \n
                                              - Date\n
                                                \n
                                                - Description:<\/b> Defines a date.\n <\/li>\n
                                                - ISO synonym:<\/b><\/li>\n
                                                - Oracle:<\/b>date<\/li>\n<\/ul>\n<\/li>\n
                                                - Datetime\n
                                                  \n
                                                  - Description:<\/b> Defines a date that is combined with a time of day with fractional seconds that is based on a 24-hour clock.\n <\/li>\n
                                                  - ISO synonym:<\/b><\/li>\n
                                                  - Oracle:<\/b>date, Fractional parts of a second are truncated<\/li>\n<\/ul>\n<\/li>\n
                                                  - Datetime2\n
                                                    \n
                                                    - Description:<\/b>Defines a date that is combined with a time of day that is based on 24-hour clock. datetime2 can be considered as an extension of the existing datetime type that has a larger date range, a larger default fractional precision, and optional user-specified precision.\n <\/li>\n
                                                    - ISO synonym:<\/b><\/li>\n
                                                    - Oracle:<\/b>timestamp<\/li>\n<\/ul>\n<\/li>\n
                                                    - Datetimeoffset\n
                                                      \n
                                                      - Description:<\/b> Defines a date that is combined with a time of a day that has time zone awareness and is based on a 24-hour clock.\n <\/li>\n
                                                      - ISO synonym:<\/b><\/li>\n
                                                      - Oracle:<\/b>timestamp with time zone<\/li>\n<\/ul>\n<\/li>\n
                                                      - Smalldatetime\n
                                                        \n
                                                        - Description:<\/b>Defines a date that is combined with a time of day. The time is based on a 24-hour day, with seconds always zero (:00) and without fractional seconds.\n <\/li>\n
                                                        - ISO synonym:<\/b><\/li>\n
                                                        - Oracle:<\/b>date, The value for seconds is returned as 0<\/li>\n<\/ul>\n<\/li>\n
                                                        - time\n
                                                          \n
                                                          - Description:<\/b> Defines a time of a day. The time is without time zone awareness and is based on a 24-hour clock.\n <\/li>\n
                                                          - ISO synonym:<\/b><\/li>\n
                                                          - Oracle:<\/b>timestamp<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n

                                                            ## Data Type Synonyms (Transact-SQL)<\/h2>\n

                                                            \nData type synonyms are included in SQL Server for ISO compatibility. The following table lists the synonyms and the SQL Server system data types that they map to.<\/p>\n

                                                            \n

                                                            \n
                                                            SQL Server Data type synonyms<\/caption>\n
                                                            \n
                                                            \nANSI SQL Synonym<\/td>\n | SQL Server system data type<\/td>\n<\/tr>\n<\/thead>\n
                                                            \n
                                                            \nBinary varying<\/td>\n | varbinary<\/td>\n<\/tr>\n
                                                            \nchar varying<\/td>\n | varchar<\/td>\n<\/tr>\n
                                                            \ncharacter<\/td>\n | char<\/td>\n<\/tr>\n
                                                            \ncharacter<\/td>\n | char(1)<\/td>\n<\/tr>\n
                                                            \ncharacter(n)<\/td>\n | char(n)<\/td>\n<\/tr>\n
                                                            \ncharacter varying(n)<\/td>\n | varchar(n) <\/td>\n<\/tr>\n
                                                            \nDec<\/td>\n | decimal<\/td>\n<\/tr>\n
                                                            \nDouble precision<\/td>\n | float<\/td>\n<\/tr>\n
                                                            \nfloat[(n)] for n = 1-7<\/td>\n | real<\/td>\n<\/tr>\n
                                                            \nfloat[(n)] for n = 8-15<\/td>\n | float<\/td>\n<\/tr>\n
                                                            \ninteger<\/td>\n | int<\/td>\n<\/tr>\n
                                                            \nnational character(n)<\/td>\n | nchar(n)<\/td>\n<\/tr>\n
                                                            \nnational char(n)<\/td>\n | nchar(n)<\/td>\n<\/tr>\n
                                                            \nnational character varying(n)<\/td>\n | nvarchar(n)<\/td>\n<\/tr>\n
                                                            \nnational char varying(n)<\/td>\n | nvarchar(n)<\/td>\n<\/tr>\n
                                                            \nnational text<\/td>\n | ntext<\/td>\n<\/tr>\n
                                                            \ntimestamp<\/td>\n | rowversion<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n \nData type synonyms can be used instead of the corresponding base data type name in data definition language (DDL) statements, such as CREATE TABLE, CREATE PROCEDURE, or DECLARE @variable. However, after the object is created, the synonyms have no visibility. When the object is created, the object is assigned the base data type that is associated with the synonym. There is no record that the synonym was specified in the statement that created the object.\n<\/p>\n ### References:<\/span><\/h3>\n \n SQL Server datatypes<\/a><\/li>\n \nMicrosoft SQL Server data types to Oracle data types<\/a>\n<\/li>\n \nOracle datatypes to SQL Server<\/a>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":" Datatype conversion is one of the key issues when convert one dialect of SQL to another. This article documents SQL Server datatypes and how to convert it to corresponding datatype of other databases. SQL Server supplies a set of system data types that define all the types of data that can be used with SQL Server. You can also define your own data types in Transact-SQL. Data types in SQL Server are organized into the following categories: Character strings, Unicode character strings, Binary strings, Exact numerics, Approximate numerics, Date and time, Other data types. Character strings char[(n)] Description: Fixed-length, non-Unicode\u2026<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":401,"menu_order":30,"comment_status":"closed","ping_status":"open","template":"gsp_sql_translate_tt.php","meta":[],"blocksy_meta":{"styles_descriptor":{"styles":{"desktop":"","tablet":"","mobile":""},"google_fonts":[],"version":5}},"yoast_head":"\nHelp you to make better use of General SQL Parser<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n