MySQL 是一種常用的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),支持多種數(shù)據(jù)類型,包括數(shù)值類型、日期與時間類型、文本類型等。下面我將分別介紹每種類型并給出一個示例:
數(shù)值類型
CREATE TABLE example ( id INT PRIMARY KEY, age TINYINT, salary INT, score FLOAT(4,2), balance DOUBLE(10,2) ); INSERT INTO example VALUES (1, 25, 50000, 3.14, 1000.50); INSERT INTO example VALUES (2, 35, 60000, 4.99, 2000.75); SELECT * FROM example;
日期與時間類型
CREATE TABLE example ( id INT PRIMARY KEY, birthdate DATE, hiredate DATETIME, currenttime TIME, timestamp TIMESTAMP ); INSERT INTO example VALUES (1, '1995-03-10', '2021-01-01 08:00:00', '16:30:00', CURRENT_TIMESTAMP); INSERT INTO example VALUES (2, '1985-12-25', '2020-05-15 14:30:00', '09:15:00', CURRENT_TIMESTAMP); SELECT * FROM example;
文本類型
CREATE TABLE example ( id INT PRIMARY KEY, name VARCHAR(20), bio TEXT, note VARCHAR(255) ); INSERT INTO example VALUES (1, 'Alice', 'Alice is a software engineer.', 'Note: Alice is highly productive.'); INSERT INTO example VALUES (2, 'Bob', 'Bob is a data analyst and a hobbyist musician.', 'Note: Bob has excellent data analysis skills.'); SELECT * FROM example;
通過上面的示例,我們可以看到 MySQL 數(shù)據(jù)庫支持多種數(shù)據(jù)類型,用戶可以根據(jù)自己的需求進行選擇和使用。