What is the difference between a database, a table, a row and a column?
BeginnerConceptMySQL
Answer
Short answer
A database is a named container (like shop). Inside it are tables (like orders), each storing one kind of thing. A column is one attribute with a type (like total DECIMAL). A row is one record (one specific order).
Example
CREATE DATABASE shop; -- the container
USE shop;
CREATE TABLE orders ( -- a table
id INT PRIMARY KEY, -- columns ↓
customer VARCHAR(100),
total DECIMAL(10,2)
);
INSERT INTO orders VALUES (1, 'Asha', 52000.00); -- one row
In MySQL, "schema" = "database"
CREATE SCHEMA shop and CREATE DATABASE shop are the same thing in MySQL. (In PostgreSQL a schema is a folder inside a database.)
What to say in the interview
"Database is the container, a table holds one entity type, columns are typed attributes and rows are individual records. In MySQL, schema and database are synonyms."
More on MySQL
How do you set up MySQL and log in to it?BeginnerHow do you create a database, a table and see data in MySQL?BeginnerHow do you create a MySQL user for an application and give it permissions?BeginnerHow do you back up and restore a MySQL database?BeginnerWhat is a relational database?BeginnerHow do you check whether MySQL is running and which port it listens on?Beginner