training Day1

                       Commands for MySQL

Mysql is basically a set of commands which help us to store some data in our database. 

Here are the commands for Mysql:

  • create database database; - used to create database.
  • show databases; - used to show all the databases present.
  • use databasename; - used to currently use the database. After using this command only we can perform actions in it.
  • create table tablename(column1 datatype1,column2 datatype2,........); - used to create table with its attributes.
  • insert into tablename values(value1,value2,.....); - used to insert values in the table
  • show tables; - used to check tables. It will work only after we use any database.
  • drop database databasename; - used to delete / Remove database.
  • desc tablename; - used to check table description.
  • When we want to retrieve data from table we use : 
                                   Select 
                                   *      -  all columns
                                  from - table name
  • When we want to retrieve specific data or column from the database we use : 
                                 Select
                                 from   - table name
                                 where - condition (eg : city = 'Ludhiana');
  • Count command is used to tell the count of number of rows. We use command as :
                      Select count(columnname)as name from tablename;
  • To add any column to existing table we use command :
                     alter table tablename add columnname datatype;
  • To show data from particular range we use command :
                     Select * from tablename where condition >= and <=
  Example :  Select * from products where quantity >=2000 and <= 8000.

Note :- We can use OR also in similar way as we use AND.
  • By default format of date in Mysql is YY-MM-DD.
  • If we want something among range then we use command : 
                   Select * from tablename where condition between value1 AND value2;
 Example : Select * from products where quantity between 2000 AND 8000;
  • To add entries in the new column or to update value in the existing column we use command :
                   Update tablename set columnname = value;
  • If we want to add data or update any particular row we use command :
                   Update tablename set columnname = value where condition;
  • Order by - It used to arrange in ascending/descending order. We use command as :
                    Select from tablename where orderby columnname;
Note :- By default the order is ascending order.
  • Sum command :
                  Select Sum(column-name ) from tablename;
  • Distinct :- It is used in select and is used to remove duplicate entries. We use command as:
                  Select distinct(column-name) from tablename;
  • Group by :- Used to group two columns. We use command as :
                  Select from tablename group by columnname;

Comments