Learn SQL using MySQL

     SQL – Structured Query Language. It has various commands to execute. Let us the mysql to run the SQL commands.

Steps to follow:

  • ·       MySql is open source,you can run the SQL command in this environment.
  • ·       First, download the MySql from official website.
  • ·       Install it in your system.
  • ·       Login into mysql in command prompt by entering the passwords.

Enter password: ***********

  • ·       The environment is look like as follows.

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 21

Server version: 9.6.0 MySQL Community Server - GPL

  • ·       First, create  a database as my_database.

mysql> create database my_database;

Query OK, 1 row affected (0.995 sec)

  • ·       Use the my_database to run the queries.

mysql> USE my_database

Database changed

  • ·       Create a table with data elements. Here, a tablename is ‘students’, members are id,name and age.

mysql> CREATE TABLE students (

              ->      id INT PRIMARY KEY AUTO_INCREMENT,

              ->     name VARCHAR(50),

              ->     age INT

              -> );

Query OK, 0 rows affected (1.853 sec)

  • ·       To add the elements use the ‘INSERT’ query with values.

mysql> INSERT INTO students(name,age) VALUES('ajay',12),('bob',15);

Query OK, 2 rows affected (0.281 sec)

Records: 2  Duplicates: 0  Warnings: 0

  • ·       To view the table,use ‘SELECT’ query.

mysql> SELECT * FROM students;

+----+------+------+

| id | name | age  |

+----+------+------+

|  1 | ajay |   12 |

|  2 | bob  |   15 |

+----+------+------+

2 rows in set (0.082 sec)

  • ·       Again insert two rows.

mysql> INSERT INTO students(name,age) VALUES('Edward',12),('Jey',13);

Query OK, 2 rows affected (0.068 sec)

Records: 2  Duplicates: 0  Warnings: 0

  • ·       Finally, view the data using SELECT query.

mysql> SELECT * FROM Students;

+----+--------+------+

| id | name   | age  |

+----+--------+------+

|  1 | ajay   |   12 |

|  2 | bob    |   15 |

|  3 | Edward |   12 |

|  4 | Jey    |   13 |

+----+--------+------+

4 rows in set (0.029 sec)

Hope, this basic SQL Tutorial to create a database, table, inserting the data and displaying the data was done successfully. Keep coding!!!

Comments

Popular posts from this blog

How to create a XML DTD for displaying student details

Java NIO examples to illustrate channels and buffers.

How to write your first XML program?