Continuing on the Chapter MySQL Database, if in the previous article I discussed the meaning of Xampp, How to Install Xampp and continued with several components on xampp, including MySQL. This time I will discuss how to create MySQL databases and tables, of course, using Xampp. For information that I made this tutorial on purpose so that the learning process can be maximized.
1. Creating MySQL Databases and Tables Manually
The following is how to create MySQL databases and tables manually.
Please run the xampp control panel (to run apache and mysql)
Open your browser
Enter the address: http://localhost/phpmyadmin/CREATE MYSQL DATABASE
Click New - Then enter the database name - Click Create
An example of a database name is dbjnmCREATE TABLES
To create a table you must first click on the database
Please click dbjnm on the right database list
Then on the left there is "create table", please enter the table name, and fill in the number of columns according to the number of table columns that we will create.
As an example, I will create a Table with the name: tbl_baranng
Then there are 5 columns, namely: code of goods, name of goods, price of goods, number of goods, unit of goods
So how to make it like the image below:
Enter the table name and the number of columns is 5.
Click Go
Then fill in the data as shown above (if the image is not clear then you can click it)
Enter item code, item name and item unit with Type VARCHAR
Enter the price of goods and the amount of goods with type INT
Don't forget the item code is PRIMARY
If you have everything, please click SAVE
If you click SAVE, then tbl_barang will appear in the dbjnm database list
Then to enter data manually, you can click tbl_barang first
Then you click insert
Enter data manually as shown below:Enter the data then click Go.
Thus you have successfully created a DBJNM database, then created a table with the name TBL_BARANG and you can fill in the data manually.
2. Creating MySQL Databases and Tables with Coding
Creating databases and tables like step one is to create coding using the GUI or manually. You can also create databases and tables using coding.
The method is as follows:
As usual, please log in to phpmyadmin
Then click on the top menu which is SQL
Then in the fields, enter some of the coding below and if you have clicked GO.
Coding To Create Database
CREATE DATABASE IF NOT EXISTS dbjnm;
Coding To Make Tables
CREATE TABLE `tbl_barang` (
`kodebarang` varchar(6) NOT NULL,
`namabarang` varchar(50) NOT NULL,
`hargabarang` int(11) NOT NULL,
`jumlahbarang` int(11) NOT NULL,
`satuanbarang` varchar(30) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `tbl_barang`
ADD PRIMARY KEY (`kodebarang`);
Coding to fill in the data on item
INSERT INTO `tbl_barang` (`kodebarang`, `namabarang`, `hargabarang`, `jumlahbarang`, `satuanbarang`) VALUES
('BRG001', 'kOPI ABC', 2500, 50, 'SACHET');
Thus the MySQL database tutorial, namely how to create databases and tables. Which in essence you can make it manually and with syntax or coding. If the article above is useful, you can comment below.
Apart from being a programming information medium, we also share articles related to Android trick tips.
0 Response to "How to Create Databases and Tables Using MySQL"
Post a Comment