Introduction
String types store words, sentences, or any text data in a database. They help keep information like names, descriptions, or messages.
column_name VARCHAR(length) column_name CHAR(length) column_name TEXT
name VARCHAR(50)
code CHAR(5)
description TEXTCREATE TABLE products ( id INT PRIMARY KEY, name VARCHAR(30), sku CHAR(8), details TEXT ); INSERT INTO products VALUES (1, 'Coffee Mug', 'MUG123 ', 'A ceramic mug for coffee.'), (2, 'Notebook', 'NOTE456 ', 'A ruled notebook with 100 pages.'); SELECT id, name, sku, details FROM products;
VARCHAR stores variable-length strings efficiently, saving space for shorter values.CHAR is fixed-length and wastes space if data varies; TEXT is for large text; BLOB is for binary data.description that can hold up to 255 characters using VARCHAR in MySQL?description VARCHAR(255) uses correct syntax; description TEXT(255) uses wrong type; description CHAR(255) uses fixed-length CHAR; description VARCHAR misses length.users with a username CHAR(10) column, what will be the result of this query?INSERT INTO users (username) VALUES ('bob');
SELECT username, LENGTH(username) FROM users WHERE username = 'bob';notes TEXT. You try to insert a string longer than 65,535 characters and get an error. What is the likely cause and how to fix it?Pass the test and this pattern moves unknown