SQL Notes
SQL Notes
DATABASE:
1.Creating database
2.Show database
3.Drop database
4.DROP database IF EXISTS
5.Use database
6.SHOW TABLES
DATA TYPES:
1.INT
2.CHARACTER
*CHAR (fixed length)
*VARCHAR (non-fixed length)
3.Decimal Numbers
4.Temporal Data
TABLE:(Create,Delete,Alter)
1.CREATE TABLE
2.DROP TABLE
3.DESCRIBE table name
4.ALTER TABLE name ADD name VARCHAR(5)
5.ALTER TABLE name DROP COLUMN name
INSERTING DATA:
1.INSERT INTO name VALUES(1,"Aarthi",7.6)
2.INSERT INTO name(id,name) VALUES(5,"Balaji"),(6,"Chandru")
//EXAMPLE
CREATE DATABASE Sportsshop;
CREATE DATABASE Sports;
DROP DATABASE Sports;
DROP DATABASE IF EXISTS Sports;
USE Sportsshop;
= Equal
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
<> Not equal
BETWEEN-Between a certain range
LIKE-search for a pattern
IN-To specify multiple possible values for a column
NOT-negation
AND/OR
LIMIT
EXAMPLE:
delete from teams
where id=11;
update teams
set MANAGEMENT="BATTING COACH"
WHERE ID =1;
Distinct:
SELECT DISTINCT coloumn name
FROM table name;
EXAMPLE:
select distinct management
from teams;
Order By:
example:
select * from teams
order by teamname;
select * from teams
order by venue asc;
select * from teams
order by totalplayers desc;
select * from teams
where TOTALPLAYERS<20
order by teamname;
Select * from teams
order by teamname,venue;
select * from teams
order by (case management
when "FIELDING COACH" then 1
when "BATTING COACH" then 2
else 100 end);