In this tutorial of creating a database and table in MySQL and inserting data into it, we are going to use MySQL Workbench and XAMPP Server. First of all, start the MySQL server and Apache Server from the XAMPP Control panel and then open your MySQL Workbench. Now that you have done that let's get started with.
Step1: Creating a Database
- Syntax: create databases database_name; (it creates a database of the name you have given ). Example: create database demo;
- Syntax: use database_name; (this syntax enables/selects the database in which you want to work). Example: use demo;
Step2: Creating a Table
- Syntax: create table table_name(column_name1 type(size), column_name2 type(size), column_name3 type(size), column_name4 type(size));. Example: create table detail(id int, name varchar (50), surname varchar (50), phone varchar (12), gender varchar (1));
Step3: Display the Table
- Synatx: select cloumn_name or *(it selects all the column of a table) from table_name; Example: select * from detail;
Step4: Inserting values in the Table
- Syntax: insert into table_name(column_name1, column_name2, column_name3, column_name4) values(column_name1value, column_name2value,column_name3value, column_name4value);. Example: insert into detail(id,name,surname,phone,gender)VALUES(1,"Ramesh","Kumar","9987212324","M");
Step4: Inserting multiple values in the Table simultaneously
- Syntax: insert into table_name(column_name1, column_name2, column_name3, column_name4) values(column_name1value, column_name2value,column_name3value, column_name4value),(column_name1value, column_name2value,column_name3value, column_name4value);. Example: insert into detail(id,name,surname,phone,gender)VALUES(2,"Karishma","Sharma","7777213224","F"),(3,"Megha","Kashyap","8876904534","F");.
Step4: Deleting a Table
- Syntax: drop table table _name. Example: drop table detail.
This is how you can create a database and a table and insert data in the table in MySQL.
Thank you
No comments:
Post a Comment
សូមអរគុណ!