SQL (Structured Query Language) is the most popular type of database. A query language is a programming language that handles information stored in a database. SQL is a relational database. It allows the programmer to define data relationship rules and then SQL enforces those rules.
When you think about SQL, imagine an Excel spreadsheet. There are columns and rows which make individual data entries. Each data entry is like a cell on a spreadsheet, and each database table is like an individual spreadsheet.
SQL Table
Here is an example of MySQL code to create a table:
CREATE TABLE users (
id INT(6) AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
email VARCHAR(40) NOT NULL,
password VARCHAR(100) NOT NULL,
signup_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP)
SQL Insert Statement
Data is inserted into the database using an insert statement. Let’s use MySQL to insert data into our users table:
INSERT INTO Users
(username, email, password)
VALUES
('candy_cane', 'candy@lampp.org', 'jk7^9hUy9gBUI&*hj!'),
('caprica6', 'caprica6@basestar.gov', 'k*&bnlo&98Hi3n'),
('bad_wolf', 'lilwolf@gmail.com', 'Megal8395$');
Relational Databases
Relational databases allow you to store, and access, information that relates to other information. They are based on the Relational Model, where data is stored in relations. A relation is a database table, like users from the example above. Each table row is a record, representing one person or thing, and each row is identified by a key. A primary key is a unique number that identifies a database record.
The relational concepts in SQL are based on mathematical concepts such as set theory. Set theory is an important area of study for SQL developers.