im@markvi.eu

SQL (Struc­tured Query Lan­guage) is like the lan­guage you use to talk to your data­base. Think of it like you’re ask­ing your com­put­er to give you some infor­ma­tion it has stored, or you want to tell the com­put­er to add new infor­ma­tion to its memory. 

Imag­ine you have a big book­shelf where you store all your books, SQL is like ask­ing your friend to go get a spe­cif­ic book you want to read or ask­ing them to add a new book to the bookshelf.

You use spe­cif­ic phras­es, called com­mands” in SQL to get things done, like SELECT and INSERT. SELECT is like ask­ing your friend to show you a cer­tain book, and INSERT is like ask­ing your friend to put a new book on the book­shelf. Pret­ty much every big com­pa­ny uses SQL to inter­act with the data­bas­es of their soft­ware, and it’s a stan­dard in the industry.

Cre­ate data­base #

To cre­ate a data­base in SQL, you can use the CRE­ATE DATA­BASE state­ment. Here is an example:

CREATE DATABASE mydatabase;

Cre­ate table #

Here is an exam­ple of a CRE­ATE TABLE state­ment in SQL:

CREATE TABLE users (
    user_id INTEGER PRIMARY KEY,
    username TEXT NOT NULL,
    password TEXT NOT NULL,
    email TEXT NOT NULL
);

This cre­ates a table called users with four columns: user_​id, user­name, pass­word, and email. The user_​id col­umn is an inte­ger and is the pri­ma­ry key for the table, mean­ing that it is unique for each row. The user­name, pass­word, and email columns are all text val­ues and can­not be NULL.

Insert data #

To insert data into the table, you can use an INSERT state­ment like this:

INSERT INTO users (username, password, email)
VALUES ('john', 'password123', 'john@example.com');

Update state­ment #

To update a record in a data­base table, you can use the UPDATE state­ment in SQL. Here is the gen­er­al syn­tax for an UPDATE state­ment. For exam­ple, to update the email address of a user with a spe­cif­ic user_​id in the users table, you can use the fol­low­ing UPDATE statement:

UPDATE users
SET email = 'newemail@example.com'
WHERE username = 'john';

Delete records #

To delete data from a data­base table in SQL, you can use the DELETE state­ment. Here is the gen­er­al syn­tax for a DELETE state­ment. For exam­ple, to delete a user with a spe­cif­ic user_​id from the users table, you can use the fol­low­ing DELETE statement:

DELETE FROM users WHERE user_id = 123;

This will delete the row with user_​id 123 from the users table.

Similar Articles