0% found this document useful (0 votes)
84 views6 pages

MYSQL

This document outlines basic MySQL syntax for creating and manipulating databases and tables. Key points include using CREATE DATABASE to make a new database, CREATE TABLE to define a table with columns and data types, INSERT to add rows of data to a table, SELECT to retrieve data from a table, UPDATE and DELETE to modify table data, and DROP to remove databases and tables. Aggregate functions like COUNT, MAX, MIN, AVG, and SUM are also covered for performing calculations on column values.

Uploaded by

Ligo Pasti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views6 pages

MYSQL

This document outlines basic MySQL syntax for creating and manipulating databases and tables. Key points include using CREATE DATABASE to make a new database, CREATE TABLE to define a table with columns and data types, INSERT to add rows of data to a table, SELECT to retrieve data from a table, UPDATE and DELETE to modify table data, and DROP to remove databases and tables. Aggregate functions like COUNT, MAX, MIN, AVG, and SUM are also covered for performing calculations on column values.

Uploaded by

Ligo Pasti
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

MYSQL

SYNTAX (BASIC)

DATABASE RELATED:
1.create database database_name; -for creating
Database.

eg: create database bloodbank;

2.show databases; -for showing all database name in


MYSQL.

3.use database_name; -for using Database.

eg: use bloodbank;

4:drop database database_name; -for permanently


deleting database.

eg: drop database bloodbank;

TABLE CREATION RELATED:


1.create table table_name(col_name1
datatype(size),col_name2
datatype(size).....col_nameN datatype(size)); -for
table creation.7
eg: create table blood (id int(2),name varchar(11),bg
varchar(11),phno
varchar(11));

NOTE: phno is varchar because int cannot accept large


number

2.show tables; -for showing all tables exist in a particular


Database.

3.desc table_name; -for showing table details.

eg: desc blood;

4.alter table table_name add column column_name


datatype(size);

-for adding new columns.

NOTE: The new column values are NULL for existing


rows

eg: alter table blood add column address varchar(10);

5.alter table table_name modify column col_name


datatype(size);

-for modifying existing columns datatype.

eg: alter table blood modify column address


varchar(20);

6.drop table table_name; -for permanently removing


table.

eg: drop table blood;


TABLE OPERATIONS
RELATED:
1.INSERTION RELATED:

i) insert into table_name values (val1,val2),


(val1,val2)...(v1,v2);

- for inserting values in all columns.

eg: insert into blood values


(1,"harish","AB+","8883100000","mahal"),

(2,"sri","B+","8883111111","mahal");

ii) insert into table_name (col_name) values (val),


(val)...(v);

- for inserting values in particular columns.

eg: insert into blood (id,name) values (1,"aravind"),


(2,"hari");

2. update table_name set col_name1=value where


col_name2=value;

- for updating values in table.

eg: update blood set name="swetha" where id=2;

3.SELECTION RELATED:

i) select * from table_name;

- for selecting all columns.


eg: select * from blood;

ii). select colname1,colname2 from table_name;

-for selecting particular columns from a table.

eg: select name,bg from blood;

iii). select colname1 from table_name where


col_name2=val;

- for selecting particular data.

eg: select name from blood where bg="AB+";

4.delete from table_name where colname=val;

- for deleting a particular row

eg: delete from blood where name="harish";

//harish row get deleted

NOTE: if where condition is ignored, all rows get deleted.


And it is equivalent to truncate table blood;

(i.e)truncate table table_name;

AGGREGATE FUNCTIONS:
1.max(col_name):
-for displaying largest value in a column based on
Numbers.

-for displaying largest value in a column based on


Alphabets.

2.min(col_name):

-for displaying smallest value in a column based on


Numbers.

-for displaying smallest value in a column based on


Alphabets.

3.sum(col_name):

-for adding values in a column

4.avg(col_name):

-for calculating average of numbers in a column.

5.count(col_name):

-for counting number of values in a column.

orderby:
Used to arrange values of a column in either ascending
or descending.

eg: select * from blood orderby name asc;

-name column values are arranged in ascending order,


which

also arrange corresponding values in other columns.

eg: select * from blood orderby name desc;


-name column values are arranged in descending
order, which

also arrange corresponding values in other columns.

NOTE: If nothing is given near orderby, it takes as "asc" in


default.

You might also like