MariaDB creating Tables

First you need to make sure you are using the correct database (if don’t know how, it was explained in previous post).
So in order to create table we need to use CREATE TABLE command.

The simple structure is following:
CREATE TABLE <tableName> (<columnName1> <type1>, <columnName2> <type2>,...);
The list of data types for MariaDb is long, but for our example we will use the INT data type (which is Integer from -2147483648 to 2147483647 signed), and  TEXT (which is a text that has a maximum length of 65,535 characters).

We will create the table employee, and it will have 4 columns, the first name of the employee, his last name, his employee number and last his salary.


MariaDB [firstDB]> CREATE TABLE employee (first_name TEXT, last_name TEXT, employee_number INT, salary INT);
Query OK, 0 rows affected (0.38 sec)

If you have not selected a database then you may get the following error ERROR 1046 (3D000): No database selected to solve this just run the USE command with the database you want to work on.

 

If we want to see all the tables in the  database we can use the command:
SHOW TABLES;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s