{"id":3902,"date":"2025-06-06T19:05:00","date_gmt":"2025-06-06T19:05:00","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=3902"},"modified":"2025-06-07T09:54:24","modified_gmt":"2025-06-07T09:54:24","slug":"sql-data-types","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/sql\/sql-data-types\/","title":{"rendered":"SQL Data Types"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">SQL Data Types (Oracle, MySQL, PostgreSQL, SQL Server)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Choosing the right data type for each column is key to ensuring data integrity, optimizing storage, and improving performance. Different database systems support various data types \u2014 here\u2019s a comprehensive overview for <strong>Oracle<\/strong>, <strong>MySQL<\/strong>, <strong>PostgreSQL<\/strong>, and <strong>SQL Server<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u270d\ufe0f Why Data Types Matter<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure <strong>correct data storage<\/strong> (e.g., numbers, text, dates)<\/li>\n\n\n\n<li>Enforce <strong>data validity<\/strong> and constraints<\/li>\n\n\n\n<li>Optimize <strong>performance and storage space<\/strong><\/li>\n\n\n\n<li>Enable database engine to perform proper operations<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u2699\ufe0f Common SQL Data Types by DBMS<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Type Category<\/th><th>Oracle<\/th><th>MySQL<\/th><th>PostgreSQL<\/th><th>SQL Server<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td>Integer<\/td><td><code>NUMBER(p)<\/code> (precision \u2264 38), <code>BINARY_INTEGER<\/code><\/td><td><code>INT<\/code>, <code>TINYINT<\/code>, <code>SMALLINT<\/code>, <code>BIGINT<\/code><\/td><td><code>INTEGER<\/code>, <code>SMALLINT<\/code>, <code>BIGINT<\/code><\/td><td><code>INT<\/code>, <code>SMALLINT<\/code>, <code>BIGINT<\/code><\/td><td>Whole numbers<\/td><\/tr><tr><td>Decimal\/Floating<\/td><td><code>NUMBER(p,s)<\/code>, <code>FLOAT<\/code>, <code>BINARY_FLOAT<\/code>, <code>BINARY_DOUBLE<\/code><\/td><td><code>DECIMAL<\/code>, <code>FLOAT<\/code>, <code>DOUBLE<\/code><\/td><td><code>NUMERIC<\/code>, <code>REAL<\/code>, <code>DOUBLE PRECISION<\/code><\/td><td><code>DECIMAL<\/code>, <code>FLOAT<\/code>, <code>REAL<\/code><\/td><td>Numbers with decimals<\/td><\/tr><tr><td>String\/Text<\/td><td><code>VARCHAR2(size)<\/code>, <code>CHAR(size)<\/code>, <code>CLOB<\/code><\/td><td><code>VARCHAR<\/code>, <code>TEXT<\/code>, <code>CHAR<\/code><\/td><td><code>VARCHAR<\/code>, <code>TEXT<\/code>, <code>CHAR<\/code><\/td><td><code>VARCHAR<\/code>, <code>TEXT<\/code>, <code>CHAR<\/code><\/td><td>Variable\/fixed-length text<\/td><\/tr><tr><td>Date &amp; Time<\/td><td><code>DATE<\/code> (includes time), <code>TIMESTAMP<\/code>, <code>INTERVAL<\/code><\/td><td><code>DATE<\/code>, <code>DATETIME<\/code>, <code>TIMESTAMP<\/code><\/td><td><code>DATE<\/code>, <code>TIMESTAMP<\/code><\/td><td><code>DATE<\/code>, <code>DATETIME<\/code>, <code>TIME<\/code><\/td><td>Dates and timestamps<\/td><\/tr><tr><td>Boolean<\/td><td>No native boolean (use <code>NUMBER(1)<\/code> or <code>CHAR(1)<\/code> for flags)<\/td><td><code>BOOLEAN<\/code> (alias for <code>TINYINT(1)<\/code>)<\/td><td><code>BOOLEAN<\/code><\/td><td><code>BIT<\/code><\/td><td>True\/False flags<\/td><\/tr><tr><td>Binary<\/td><td><code>BLOB<\/code>, <code>RAW<\/code>, <code>LONG RAW<\/code><\/td><td><code>BLOB<\/code>, <code>BINARY<\/code><\/td><td><code>BYTEA<\/code><\/td><td><code>VARBINARY<\/code>, <code>BINARY<\/code><\/td><td>Binary data (files, images)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde9 Examples for Each DBMS<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Oracle<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE TABLE employees (\n  id NUMBER(10) PRIMARY KEY,\n  name VARCHAR2(100),\n  salary NUMBER(10, 2),\n  hire_date DATE,\n  is_active NUMBER(1) -- 0 = false, 1 = true\n);<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">MySQL<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE TABLE employees (\n  id INT AUTO_INCREMENT PRIMARY KEY,\n  name VARCHAR(100),\n  salary DECIMAL(10, 2),\n  hire_date DATE,\n  is_active BOOLEAN\n);<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">PostgreSQL<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE TABLE employees (\n  id SERIAL PRIMARY KEY,\n  name VARCHAR(100),\n  salary NUMERIC(10, 2),\n  hire_date DATE,\n  is_active BOOLEAN\n);<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">SQL Server<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>CREATE TABLE employees (\n  id INT IDENTITY(1,1) PRIMARY KEY,\n  name VARCHAR(100),\n  salary DECIMAL(10, 2),\n  hire_date DATE,\n  is_active BIT\n);<\/code><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udca1 Tips for Working with Data Types<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Oracle\u2019s <code>NUMBER<\/code> type is versatile \u2014 define precision and scale carefully for your needs.<\/li>\n\n\n\n<li>Use <code>VARCHAR2<\/code> in Oracle, <strong>not<\/strong> <code>VARCHAR<\/code> (deprecated).<\/li>\n\n\n\n<li>For boolean values in Oracle, typically use <code>NUMBER(1)<\/code> or <code>CHAR(1)<\/code> with conventions (<code>1<\/code>\/<code>0<\/code> or <code>Y<\/code>\/<code>N<\/code>).<\/li>\n\n\n\n<li>Always size string types appropriately to save space (e.g., <code>VARCHAR2(50)<\/code> instead of <code>VARCHAR2(4000)<\/code> if possible).<\/li>\n\n\n\n<li>Use <code>CLOB<\/code> (Oracle) or <code>TEXT<\/code> (others) for large text fields.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 Quick Recap<\/h2>\n\n\n\n<figure class=\"wp-block-table has-small-font-size\"><table><thead><tr><th>Data Type<\/th><th>Oracle Example<\/th><th>Purpose<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>Integer<\/td><td><code>NUMBER(10)<\/code><\/td><td>Whole numbers<\/td><td>Oracle uses flexible NUMBER<\/td><\/tr><tr><td>Decimal<\/td><td><code>NUMBER(10,2)<\/code><\/td><td>Decimal numbers<\/td><td>Precision and scale specified<\/td><\/tr><tr><td>String\/Text<\/td><td><code>VARCHAR2(100)<\/code><\/td><td>Variable-length strings<\/td><td>Use VARCHAR2 in Oracle<\/td><\/tr><tr><td>Date &amp; Time<\/td><td><code>DATE<\/code>, <code>TIMESTAMP<\/code><\/td><td>Date and time values<\/td><td>Oracle <code>DATE<\/code> includes time<\/td><\/tr><tr><td>Boolean<\/td><td><code>NUMBER(1)<\/code> or <code>CHAR(1)<\/code><\/td><td>True\/False flags<\/td><td>No native boolean in Oracle<\/td><\/tr><tr><td>Binary<\/td><td><code>BLOB<\/code>, <code>RAW<\/code><\/td><td>Binary data<\/td><td>For files, images, etc.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>SQL Data Types (Oracle, MySQL, PostgreSQL, SQL Server) Choosing the right data type for each column is key to ensuring data integrity, optimizing storage, and improving performance. Different database systems support various data types \u2014 here\u2019s a comprehensive overview for Oracle, MySQL, PostgreSQL, and SQL Server. \u270d\ufe0f Why Data Types Matter \u2699\ufe0f Common SQL Data [&hellip;]<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,979],"class_list":["post-3902","cposts","type-cposts","status-publish","hentry","category-notes","category-sql"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/3902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=3902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=3902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}