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 :
from - table name
where - condition (eg : city = 'Ludhiana');
- Count command is used to tell the count of number of rows. We use command as :
- To add any column to existing table we use command :
- To show data from particular range we use command :
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 :
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 :
- If we want to add data or update any particular row we use command :
- Order by - It used to arrange in ascending/descending order. We use command as :
Note :- By default the order is ascending order.
- Sum command :
- Distinct :- It is used in select and is used to remove duplicate entries. We use command as:
- Group by :- Used to group two columns. We use command as :
Comments
Post a Comment