0% found this document useful (0 votes)
2 views3 pages

SQL Notes

The document provides a comprehensive overview of basic SQL queries, including database creation, data types, table management, data insertion, and selection with conditions. It includes examples of SQL commands for creating databases and tables, inserting data, using the WHERE clause, and performing updates and deletions. Additionally, it covers the use of DISTINCT and ORDER BY clauses for data retrieval and organization.

Uploaded by

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

SQL Notes

The document provides a comprehensive overview of basic SQL queries, including database creation, data types, table management, data insertion, and selection with conditions. It includes examples of SQL commands for creating databases and tables, inserting data, using the WHERE clause, and performing updates and deletions. Additionally, it covers the use of DISTINCT and ORDER BY clauses for data retrieval and organization.

Uploaded by

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

SQL BASIC QUERIES

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;

CREATE TABLE ITEMS(


id INT PRIMARY KEY,
NAME VARCHAR(30),
Price INT
);
ALTER TABLE ITEMS ADD rating INT;
ALTER TABLE ITEMS ADD GST INT;
ALTER TABLE ITEMS DROP GST;
ALTER TABLE ITEMS DROP rating;

INSERT INTO ITEMS VALUES(2,"Football",300);


DESCRIBE ITEMS;
SELECT * FROM ITEMS;
INSERT INTO ITEMS VALUES
(3,"cricketbat",500),
(4,"cricketball",50),
(5,"tennisbat",400);

INSERT INTO ITEMS (ID,NAME) VALUES(6,"Tennisball");

SELECT id,price FROM ITEMS;


WHERE CLAUSE AND CONDITIONS:
//Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;

= 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:select * from TEAMS


where TEAMNAME="mumbai indians";

select * from TEAMS


where TEAMNAME<>"mumbai indians";

select ID,TEAMNAME from TEAMS


where TEAMNAME<>"mumbai indians";

select * from TEAMS


where TOTALPLAYERS>=20;

select * from TEAMS


where TOTALPLAYERS<=20;

select * from TEAMS


where totalplayers<20 AND VENUE="CHEPAUK STADIUM";

select * from TEAMS


where totalplayers IN (15,20);

select TOTALPLAYERS from TEAMS


where VENUE="CHEPAUK STADIUM";

select * from TEAMS


where TEAMNAME LIKE 'R%';

select * from TEAMS


where TOTALPLAYERS BETWEEN 15 AND 19;

select * from TEAMS


LIMIT 8;

select * from TEAMS


where TEAMNAME LIKE '%E%';

select * from TEAMS


where TEAMNAME LIKE '__N%';
LIKE
WILDCARDS
% represents zero or more characters
_ represents exactly one character

UPDATE AND DELETE


UPDATE Table-name
SET coloumn-name
DELETE FROM
DELETE from Tablename
WHERE

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);

You might also like