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 linkMySQL Workbench
You can download it through this link
NOTE:
- Install and set up the community server first.
- The earliest version of MySQL workbench has some issues on Mac so you can install an older version.
- 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:
You can click the existing connection or create a new connection clicking the (+) symbol next to “MySQL Connections”.
You can name your new connection, then click ok.
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.
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’.
You can add a name to the new schema created and click apply.
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.
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.
Lets add more columns named ,Emp name(Employee Name),Emp dept(Employee Department) ,and Emp salary(Employee Salary).
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.
Click apply and you’ll see the new table under tables.
You can insert values into the table with the Insert Into syntax.
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’.
Then you browse or locate the csv file you want to load.
Then you click next, till the table is successfully imported.
You can then refresh your schema and click on table and select it.
Hope you enjoyed this article, thanks for reading, please like, share and comment your thoughts.
Top comments (0)