Introduction
Choosing the right data type helps your database store information efficiently and work faster.
Choosing the right data type helps your database store information efficiently and work faster.
CREATE TABLE table_name ( column_name data_type(size), ... );
CREATE TABLE users ( id INT, name VARCHAR(100), birthdate DATE );
CREATE TABLE products ( product_id INT, price DECIMAL(10,2), description TEXT );
This example creates an employees table with proper data types for each column, inserts two rows, and selects all data.
CREATE TABLE employees ( employee_id INT, first_name VARCHAR(50), last_name VARCHAR(50), salary DECIMAL(8,2), hire_date DATE ); INSERT INTO employees VALUES (1, 'Alice', 'Smith', 55000.00, '2020-01-15'); INSERT INTO employees VALUES (2, 'Bob', 'Jones', 62000.50, '2019-07-30'); SELECT * FROM employees;
Using too large data types wastes space and slows down queries.
Using too small data types can cause errors or data loss.
Always pick data types that match the kind of data you expect to store.
Correct data types save space and improve speed.
They help keep your data accurate and safe.
Choosing data types carefully makes your database work better.
CREATE TABLE products (id INT, price DECIMAL(6,2));INSERT INTO products VALUES (1, 1234.567);?VARCHAR(10) but you want to store longer text. Which fix is correct?A) INTB) VARCHAR(15)C) CHAR(15)D) BIGINTPass the test and this pattern moves unknown