DEV Community

Cover image for Getting Started With SQL
EzeanaMichael
EzeanaMichael

Posted on

Getting Started With SQL

SQL is an acronym for Standard Query Language. It is a language used in the management of databases within software packages. A database is a group of records logically related to one another and stored electronically on a computer. SQL is used to run efficient queries to derive insight and manage databases differently. A DBMS which stands for database management system is a software package used for managing and manipulating databases efficiently, these are done with the standard query language, SQL. There are different database management systems including Microsoft Access, MongoDB, MySQL, PostgreSQL, and so on. In this series, we’ll be using MySQL to learn commands in SQL and how to run some efficient queries.

How to install MySQL

To run SQl on your personal computer, you’ll need to install 2 software.

  • MySQL community server
    You can download it through this link

  • MySQL Workbench
    You can download it through this link

NOTE:

  1. Install and set up the community server first.
  2. The earliest version of MySQL workbench has some issues on Mac so you can install an older version.
  3. Remember the password you used when setting up MySQL, you’ll need it to access your databases.

After installing the MySQL community server and MySQL Workbench. You can open the workbench, you’ll see a database and a page that looks like this:

Image description
You can click the existing connection or create a new connection clicking the (+) symbol next to “MySQL Connections”.

Image description
You can name your new connection, then click ok.

Image description
Once the new connection has shown, you and click on it. A password request will show up and you can use the registered password you set when installing the package.

Image description

Image description

Creating a new schema in MySQL

A schema in a database describes how tables are related and connected to one another. When you click the dropdown arrow in schema, you’ll see functions, tables, views and stored procedures.
To create a new schema, right click on the section labeled schemas and click ‘create schema’.

Image description
You can add a name to the new schema created and click apply.

Image description

After doing this, refresh your schema’s page if it doesn’t show up, or restart the application.

Creating a new table in MySQL

To create a table in sql, you can click the dropdown arrow on the newly created schema and right click on tables and click create table.

Image description

Image description

Name your table and you can add columns by clicking under the column where ’click to edit’ is written. You can create a primary key by clicking the box under ‘pk’ and ‘nn’ standing for not null. The datatype can also be changed to either int, char and so on.
I named my table employee table and created a column named ‘empid’(Employee ID), which I made to be the primary key.

Image description

Lets add more columns named ,Emp name(Employee Name),Emp dept(Employee Department) ,and Emp salary(Employee Salary).

Image description

After creating your columns you click apply.When you do, you’ll see a box which shows a possible SQL command you could write to do this automatically.

Image description

Click apply and you’ll see the new table under tables.

Image description
You can insert values into the table with the Insert Into syntax.

Image description

Image description

We will see more on how to use syntax like this in the coming articles.
You can click the table icon next to employee table to display the table after running the command.

Importing table in MySQL

While using SQL ,sometimes you’ll need to manage existing tables stored on some other part of the computer in the database, you can import those documents following these steps.

First, right-click the label ‘Tables’ under the new schema and select ‘table data import wizard’.

Image description

Then you browse or locate the csv file you want to load.

Image description

Then you click next, till the table is successfully imported.
You can then refresh your schema and click on table and select it.

Image description

Hope you enjoyed this article, thanks for reading, please like, share and comment your thoughts.

Top comments (0)