MySql Statements You Should Know

mysql-statement

MySql Statements You Should Now

MySQL is the world’s most popular open source database that is widely used in desktop and web applications that is why it is a good thing to know the basic MySql Statements that you can use to it. I already showed you on how to install MySql server and on how to MySq connector .net to connect it to Visual Studio, now I will list down some of the basic MySql Statements that you should know before you start designing and coding your database driven application.

It is much easier to use a database management tool like MySql workbench when writing MySql Statements, but if you don’t have one you can use MySql Command Line Client.

mysql-statement

How to list available MySql database on your server

show databases;

How to create new MySql database

create database myfirstdb;

If you are going to use MySql Command Line Client once your database has been created, you will need to select it in order to begin editing it. You will need to use the command USE;

use myfirstdb;

mysql-statement

How to create new MySql table

CREATE TABLE student_info
(
`StudentID` bigint(20) NOT NULL auto_increment,
`Code` varchar(20) NOT NULL,
`Name` varchar(20) NOT NULL
);


How to add a column in an existing MySql table

CREATE TABLE student_info
(
`StudentID` bigint(20) NOT NULL auto_increment,
`Code` varchar(20) NOT NULL,
`Name` varchar(20) NOT NULL
);

How to remove column in an existing MySql table

ALTER TABLE student_info DROP COLUMN `Name`;

How to add column in an existing MySql table

ALTER TABLE student_info ADD `FirstName` varchar(20) NOT NULL;
ALTER TABLE student_info ADD `Last-Name` varchar(20) NOT NULL;

How to modify column name of MySql table

ALTER TABLE `student_info` CHANGE COLUMN `Last-Name` `LastName` VARCHAR(20) NOT NULL;

How to modify datatype or size of column of MySql table

ALTER TABLE student_info MODIFY COLUMN LastName VARCHAR(25);
Liked it? Take a second to support denricdenise on Patreon!

You may also like...