Monday, 19 February 2018

Mysql Basic Commands

Create database
Create database statement is used to create a database in MySQL
Syntax:
Create database databasename;
Example:
create database lp;

Select database
It is used to select the database
Syntax:
use databasename;
Example:
use lp;

Create table:
Create table statement is used to create a table in MySQL
Syntax:
 Create table table name( fieldname1 datatype(),fieldname2 datatype()...);
Example:
create table emp(id int(10)   UNSIGNED AUTO_INCREMENT PRIMARY KEY ,name varchar(30) NOT NULL,salary decimal(7,2) NOT NULL);
Note:
salary decimal(7,2)
The first argument is precision,which is the number of total digits.The second argument is scale which is the maximum number of digits to the right of the decimal point. 
Example:
34567.23,23478.45

Insert statement:
Insert statement is used to insert data into table in MySQL
Syntax: 
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
Example:
INSERT INTO emp(id,name,salary)values(101,"Dipak",45500.78);
INSERT INTO emp(id,name,salary)values(102,"Surya",35000.90);

Select statement:
It is used to retrieve data from table.
Syntax:
SELECT statement is used to select data from one or more tables:
SELECT column_name(s) FROM table_name;
We can use the * character to select ALL columns from a table
Select*from  table name;
Example:
select*from emp;


Update statement
Update statement is used to update existing records in a table
Syntax: 
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value 
Example:
update emp set name="dev" where name="surya";


Delete statement:
delete statement is used to delete records from a table
Syntax: 
delete form table name
Or
DELETE  FROM table_name
WHERE some_column = some_value
Example:
delete from emp where id=102;

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...