Quantcast
Channel: Website Developer » INSERT
Viewing all articles
Browse latest Browse all 3

MySQL Create Table

$
0
0

This MySQL Create Table is written on Website Developer

What is a MySQL table?

The secret of storing information on web sites in an orderly way is that SQL databases, and the most popular of them-the MySQL database, in particular, consist of tables. Each MySQL table consists of columns and rows-just like the graphic chart that we know very well. The columns indicate different categories of entries in the table, while the rows contain information about the objects that need to be made an inventory of.

How to add a new table using PHPMyAdmin

The process of creating table MySQL is now easier than ever with the help of phpMyAdmin interface. With any of the hosting plans offered by NTC Hosting you get this MySQL management tool easily integrated in your web hosting control panel. To access this tool-simply login to your control panel, go to the MySQL Database, select the database that you want to create a table and click on its icon phpMyAdmin. Now you can start the ‘create new table in database’ Wizard by entering your MySQL table name and the number of fields for this particular table and pressing ‘ Go ‘. This will take you to the field of development, in which you must name each field one by one in the ‘ field ‘ column, choose their types of ‘ type ‘ drop-down menu, and enter a value for the length of each field. Then you should assign attributes to each field, select an option from the drop-down menu null Null list and define whether the field is a primary key or not. The latest action needed from you is to select the chart type and the method of collection and then press the ‘ save ‘ button to finish creating the table. For more information please check out the tutorial video below:

A video tutorial on how to create a table using the control panel and PHPMyAdmin

How to create a table using the SQL command line

Unfortunately, there are web hosting provides that do not reach their database server via PHPMyAdmin tool. In such cases, developers must establish a connection via SSH and use the SQL command line to create a table. For example, we will create a table ‘recipes’ that will have three fields for ‘ingredient’, ‘quantity’ and ‘mtype’ (per type of measure).

Note: For a detailed tutorial on how to establish an SSH connection to a MySQL host and how to log into a database, make sure the ‘MySQL’ and ‘CREATE DATABASE’ MySQL articles

An example of How to Create Table in MySQL

CREATE TABLE recipes(ingredient VARCHAR(32), quantity VARCHAR(32), mtype VARCHAR(32), address VARCHAR(64));

Once your database is created it is a good idea to add some data in it. To do so you need to use the INSERT statement and insert the data into the ‘recipes’ table (more details in the MySQL Insert article).

An example of how to Insert data into MySQL table

INSERT INTO phonebook(phone, firstname, lastname, address) VALUES('+1 123 456 7890', 'John', 'Doe', 'North America'); (inserts data into phonebook table)

When we need to call the data from our table we can use the SELECT statement. The following example will display all the data from the ingredient field

An example of how to Select data from MySQL table (1)

SELECT * FROM recipes ORDER BY ingredient;

To make our example more complex we will call the data which contains ‘chicken’ in the ‘ingredient’ field:

An example of how to Select data from MySQL table (2)

SELECT * FROM recipes WHERE ingredient = 'chicken';

If we need to call all the data which contains ’350′ as ‘quantity’ and ‘grams’ as ‘measurement type’, then our query will look like this:

An example of how to Select data from MySQL table (3)

SELECT * FROM recipes WHERE quantity = '350' AND mtype = 'grams';

If we decide to update our recipe data we need to run a simple query by using the UPDATE statement

An example of how to Update data in MySQL database

UPDATE recipes SET ingredient = 'fish' WHERE quantity = '350' AND mtype = 'grams';

In order to remove an ingredient from our recipe we will delete all records which contain ‘chicken’ and ‘grams’ in the ‘ingredient’ and ‘mtype’ fields.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images