Mohammad Farhan
Mohammad Farhan's blog

Follow

Mohammad Farhan's blog

Follow

7 MySQL commands to start as a beginner ๐Ÿ”ฐ.

Need some beginner level SQL commands to start your journey? Here it is.

Mohammad Farhan's photo
Mohammad Farhan
ยทJan 25, 2023ยท

2 min read

Table of contents

  • Suggest me a database language, you probably will say "SQL" pronounced as "Sequel".
  • 1. CREATE
  • 2. USE
  • 3. INSERT INTO
  • 4. SELECT
  • 5. UPDATE
  • 6. DROP
  • 7. SHOW

Suggest me a database language, you probably will say "SQL" pronounced as "Sequel".


SQL is a compact but powerful database language used in many popular database management servers. MySQL is a database server for manipulating, organising and retrieving data in relational or tabular form. So SQL is also based on a relational model. Let's start.

1. CREATE

CREATE command is used for many things, not just one.

CREATE USER 'FARHANSQL'@'localhost' IDENTIFIED BY 'myPassword123!';

The above statement creates a new user with FARHANSQL as a username and myPassword123! as its password.

CREATE DATABASE FOOTBALL;

The above statement creates a new database FOOTBALL.

CREATE TABLE PSG
(
PLAYERNO INTEGER NOT NULL,
NAME CHAR(20) NOT NULL,
BIRTH_DATE DATE,
GOALS SMALLINT,
ASSISTS SMALLINT,
SEX CHAR(1),
MINUTES_PLAYED INTEGER,
APPEARANCE INTEGER,
PRIMARY KEY (PLAYERNO,NAME)
);

The above statement will create a PSG table with columns enclosed in brackets.

2. USE

USE command is used to select the current database to work with. MySQL never switches to any database automatically. It should be done manually.

USE FOOTBALL;

3. INSERT INTO

INSERT INTO will populate the PSG table with values or data in their respective columns we just made above.

INSERT INTO PSG VALUES
(
30,
'Lionel Messi',
'1987-06-24',
13,
14,
'M',
1837,
21
);

Congrats, we just create our first row. This will fill our PSG table with a row, including data. Always remember in relational databases data is filled up row by row.

4. SELECT

SELECT PLAYERNO, NAME FROM PSG WHERE PLAYERNO = 30;

SELECT statements are used to retrieve data from tables.

5. UPDATE

UPDATE PSG SET GOALS = 16 WHERE PLAYERNO = 30;

This will update data on goals 13 to 16.

6. DROP

DROP TABLE PSG;

DROP command will delete any table and all its data on it.

7. SHOW

SHOW DATABASES;
SHOW TABLE;
SHOW PRIVILEGES;

So these are some very basic SQL commands and MySQL commands in general.

I recommend a try it. And feel free to contact me. And suggest to me on which topic I write my next blog.

Thanks For Reading.

Prosper in Life ๐Ÿ•Š๏ธ

ย 
Share this