SQL Data Types
09/13/2001The world of the SQL Data Definition Language (DDL), which we started exploring over the past few articles, is a world of mystery, contradiction, and occasional frustration and insanity. Most database products support a robust implementation of ANSI-SQL for manipulating data, but there is far more variance in the details of how DDL is implemented. One of the primary areas for potential danger is in the SQL data types supported by each database platform.
SQL Data Types
Last column, I introduced the SQL DDL commands for creating a table in a database:
CREATE TABLE table_name (
column_name datatype [modifiers],
(column_name datatype [modifiers],
);
Note that each column is required to have a name and a data type. Different databases, however, offer a different array of choices for the data type definition that have significant effects on performance, database size, and even sorting rules. But the general categories should be familiar to anyone that has done any programming in the past:
- strings, both fixed-length and variable-length text;
- numbers, including integers and floating point representations;
- date/time types; and
- binary types for binary data.
Each database has many variations on the individual themes. For example, integer data types often come in two or more sizes to increase the storage and calculation efficiency of algorithms underlying the database functionality. One integer, for example, may only represent values up to 65,000 or so, while another handles numbers over 2 billion. The space set aside for each of the two types of integers is different, even if the values in them are identical. Furthermore, algorithms that are efficient for sorting 65,000 records may or may not be as efficient for 2 billion, necessitating either more running time or more complex code to produce the same effect. These issues are transparent to the database user because the developers of the database itself tackled these issues, but knowing the options will allow you to make better design and implementation decisions.
SQL Data Type Quick Reference
The "same, yet different" nature of SQL data types is of vital importance for any developer working with multiple database products, or those valiantly attempting to write SQL that lives in the application layer, independent of specific database platform choices. While by no means complete, the following table outlines some of the common names of data types between the various database platforms:
| Access | SQL-Server | Oracle | MySQL | PostgreSQL | |
| boolean | Yes/No | Bit | Byte | N/A | Boolean |
| integer | Number (integer) | Int | Number | Int Integer (synonyms) |
Integer Int |
| float | Number (single) | Float Real |
Number | Float | Numeric |
| currency | Currency | Money | N/A | N/A | Money |
| string (fixed) | N/A | Char | Char | Char | Char |
| string (variable) | Text (<256) Memo (65k+) |
Varchar | Varchar Varchar2 |
Varchar | Varchar |
| binary object | OLE Object Memo |
Binary (fixed up to 8K) Varbinary (<8K) Image (<2GB) |
Long Raw | Blob Text |
Binary Varbinary |
|
Also in aboutSQL: |
As you can see, similarities abound, but there are enough differences or alternative options that we come to another nugget of SQL wisdom:
SQL Wisdom #7) The data type is invariably different -- even if it has the same name -- in another database. Always check the documentation.
Even when the name is the same, the size and other details may be different. Hopefully, you can implement everything as stored procedures and let the DBAs earn their keep making the appropriate translations!
Next Steps
Now that we can create databases and database tables, we'll need to know how to change the tables we've created. In addition, we'll have to take a quick look at data types in databases, one of the primary gotchas when moving database schemas from one platform to another. Until then, feel free to contact me with comments and questions.
John Paul Ashenfelter is president and CTO of TransitionPoint.com, a technology development and analysis group focusing on web database applications.
Read more aboutSQL columns.
Return to ONLamp.com.
-
How to import BLOB data from sybase data field(IMAGE) into excel
2010-06-14 23:47:12 kimran [View]
-
ANSI DataTypes for LOBs and Dynamic SQL
2009-04-02 12:40:48 DeniseF [View]
-
query of REFNO
2008-06-16 22:59:50 moin_rokon [View]
-
Read the image data types values
2008-06-05 01:15:35 Thizo [View]
-
reading image data type
2008-06-05 01:06:43 Thizo [View]
-
Searching for Timestamp Datatype
2008-03-14 12:13:11 pickforc [View]
-
how do i find the nth highest number
2007-12-20 00:48:47 neeraj.niranjan2@cognizant.com [View]
-
Data Types SQL
2007-12-10 10:10:21 krispon [View]
-
please help me
2007-10-29 09:47:31 mycar [View]
-
please help me
2007-10-29 09:50:59 mycar [View]
-
datatype
2007-05-09 04:13:39 phemy [View]
-
to find the second higest no?
2007-05-06 04:25:56 MySQLQuerieshelp [View]
-
datatypes
2007-04-16 01:08:53 sheebasudheer [View]
-
Email datatype
2007-03-29 08:56:15 sravy [View]
-
cognos cross tab report
2007-03-20 11:49:11 mfaridi [View]
-
i want a query
2007-02-11 02:22:33 phani16 [View]
-
difference b/t
2006-11-01 05:17:30 mridula [View]
-
data type convertion in several DBMS
2006-09-15 05:42:49 kasun_it [View]
-
Timestamp in MySQL
2006-09-05 03:37:51 kunalpawar [View]
-
help me
2006-07-27 04:35:01 yoesuf [View]
-
SQL query
2006-07-14 04:00:59 chandan@NIC [View]
-
bpo
2006-07-05 00:23:39 chellamani [View]
-
Prove that the combination of two columns are unique
2006-05-15 15:01:36 vishnulive [View]
-
Prove that the combination of two columns are unique
2006-08-18 07:52:04 PatTheDBA [View]
-
Data storage for Email
2005-10-21 06:08:17 comment [View]
-
Data storage for Email
2007-04-02 07:28:15 gayan_mc [View]
-
problem with index keys
2005-08-31 05:32:21 madhugadde [View]
-
Why doesn't the following query return me the nth highest value?
2005-07-28 07:34:41 Suneel_Gundlapalli [View]
-
Why doesn't the following query return me the nth highest value?
2006-03-27 12:25:24 jaipalreddy [View]
-
Storage level difference between Char and Binary types
2005-04-29 02:42:47 Apaku [View]
-
Storage level difference between Char and Binary types
2007-01-16 01:04:34 jack.oracle [View]
-
SQL Server components
2004-12-08 15:40:17 DanTech [View]
-
what is Tablespace and how many types of tablespace and is used inj sql /Plsql??
2004-11-14 21:51:28 Question&answer [View]
-
what is Variance and different types of variance and is used in sql and pl/sql.Pls give the answer as soon as possible.I wiil wait of your positive response.
2004-11-14 21:49:56 Question&answer [View]
-
how do we find nth highest in SQL
2004-10-08 07:32:14 gansin [View]
-
how do we find nth highest in SQL
2007-11-21 02:20:53 Ani123 [View]
-
how do we find nth highest in SQL
2009-10-13 11:57:45 Sandip D [View]
-
how do we find nth highest in SQL
2010-03-06 20:24:30 Sikindar [View]
-
how do we find nth highest in SQL
2006-05-19 05:24:47 SPKUMAR [View]
-
how do we find nth highest in SQL
2006-07-11 22:39:42 prasanna1729 [View]
-
how do we find nth highest in SQL
2005-09-25 23:55:04 lalitpant [View]
-
how do we find nth highest in SQL
2005-10-17 23:28:21 Apurva_Sharma [View]
-
how do we find nth highest in SQL
2009-10-13 12:05:05 Sandip D [View]
-
how do we find nth highest in SQL
2005-01-28 13:02:12 parangogoi [View]
-
how do we find nth highest in SQL
2005-10-17 23:29:32 Apurva_Sharma [View]
-
how do we find nth highest in SQL
2004-10-13 04:11:13 sunrek [View]
-
how do we find nth highest in SQL
2005-10-17 23:31:59 Apurva_Sharma [View]
-
how do we find nth highest in SQL
2004-11-14 21:40:07 Question&answer [View]
-
how do we find nth highest in SQL
2004-06-07 11:19:23 chand_05 [View]
-
how do we find nth highest in SQL
2005-09-21 00:22:18 SachinJindal [View]
-
What is the difference between varchar and varchar2 in ORACLE
2004-06-07 11:17:00 chand_05 [View]
-
What is the difference between varchar and varchar2 in ORACLE
2004-11-14 21:48:00 Question&answer [View]
-
What is the difference between varchar and varchar2 in ORACLE
2006-09-20 08:22:41 sravan.k [View]
-
Timestamp?
2004-05-06 01:45:35 SQLChap [View]
-
Timestamp?
2004-07-08 05:07:56 SQLChap [View]
-
different thread
2004-04-28 01:50:40 3455TGTTRG [View]
-
different thread
2004-04-28 01:48:29 3455TGTTRG [View]
-
What about ansi data types?
2003-07-02 03:47:34 anonymous2 [View]
-
Ora Data Conversion
2003-06-30 02:39:18 anonymous2 [View]
-
Select
2003-05-27 06:43:13 anonymous2 [View]
-
SQL Join on Different Data Types
2002-05-29 06:14:30 bradle [View]
-
SQL Join on Different Data Types
2003-05-07 21:50:24 anonymous2 [View]
-
SQL Data Types
2002-05-01 09:35:18 ccstompnet [View]
-
SQL Data Types
2008-05-27 03:31:17 sarab1 [View]
-
Oracle Question
2001-12-27 02:14:13 nitinp [View]



