0% found this document useful (0 votes)
10 views11 pages

Csegyan: Create Database Syntax: Show Databases

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

Csegyan: Create Database Syntax: Show Databases

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

To view available databases:

To create a database:
Syntax: show databases;
Syntax: create database <database_name>;
Eg: create database csegyan;

To use a databases:
Syntax: use <databases_name>;

*******************************************************************
To create a Table:
Syntax: CREATE TABLE <table_name> (column1 datatype (size), column2
datatype (size),...);

*** Primary key has to be mentioned***


Eg: CREATE TABLE student (name varchar(50), rollnumber int(10) not null
primary key,...);

To view a table:
Syntax: show tables;
To view a table structure:
Syntax: describe <table_name>; (or) desc <table_name>;

*******************************************************************

To insert values into a table:


a) Data is inserted without Column names
Syntax: INSERT INTO tablename VALUES (value 1, value 2,...);

b) Data is inserted with Column names


Syntax: INSERT INTO tablename (column1, column2,..) VALUES (value1,
value 2,...);

c) Data is inserted to specific Column names


Syntax: INSERT INTO table_name (column1, column2,..) VALUES
(value1, value 2,...);
Eg: INSERT INTO student ( rollnumber, name) VALUES (98, ‘ram’);
******************************************************************
Select Statement:
a) To display specific column of the table
Syntax: SELECT column1, column2 FROM table_name;

b) To display the entire table


Syntax: SELECT * FROM table_name;

c) To display table using WHERE CONDITION


Syntax: SELECT * FROM table_name WHERE condition;
Eg: SELECT * FROM student WHERE rollnumber=12;

******************************************************************
SPECIAL OPERATORS

* IS NULL
LIKE OPERATOR
* LIKE

* BETWEEN

* IN
* DISTINCT
Syntax: Select distinct column_name from table_name;

Syntax: Select count(distinct column_name) from table_name;

Syntax: Select sum(distinct column_name) from table_name;

Syntax: Select avg(distinct column_name) from table_name;

******************************************************************
AGGREGATE FUNCTIONS
* COUNT
Syntax: Select count(*) from table_name;

COUNT(*)
Counts the total number of
rows in a table, including
NULL values.

Syntax: Select count(column_name) from table_name;

COUNT(column_name)
Counts the number of
values in a specific column,
excluding NULL values.

* MAX Syntax: Select max(column_name) from table_name;

* MIN Syntax: Select min(column_name) from table_name;


* SUM Syntax: Select sum(column_name) from table_name;

* AVG Syntax: Select avg(column_name) from table_name;

******************************************************************

LOGICAL OPERATORS
* AND – Both the condition should be true

* OR – Either of the condition can be true

* NOT – Condition gives reversed result

You might also like