SQL
Structured Query Language
SQL is language use for creating, accessing and manipulating database systems. SQL statements are used to retrieve and update data in a database. SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.
Database is collection of data Stored in table format.Each table is identified by a name . Tables contain records (rows) and columns.Below is an example of a table called “employee":
Id Name Sal
1 Aditya 25000
2 Vaidehi 17000
For Performing Operations on the data stored in tables different commands are available in sql. SQL commands are categorized in different groups
DDL : Data Definition LanguageDML: Data Manipulation Language TCL : Transaction Control Language
DATA DEFINITION LANGUAGE(DDL)
DDL include three commands
•CREATE - Creates a new database table or object.• ALTER - Alters (changes) a database table or Object We can Add ,Modify and Drop column• DROP - Deletes a database table or Object
CreateSyntax:Create table table_name( column1 datatype(size), column2 datatype(size), . . columnn datatype(size));
Example:Create table Employee(id number(3), name varchar2(10), salary number(10));
EFFECT OF CREATE COMMANDId Name salary
AlterSyntax: Alter table table_name ADD/MODIFY/DROP (column specification);
Example Alter table employee Add (Address varchar2(10)); Alter table employee modify(Address varchar2(12)); Alter table employee Drop(Adress );
EFFECT OF ALTER COMMANDID NAME SALARY
Alter table employee Add (Address varchar2(10));
ID NAME SALARY ADDRESS
Alter table employee Drop(Address );
ID NAME SALARY
DropSyntax:Drop table table_name;
Example: Drop table employee;
DATA MANIPULATION LANGUAGE (DML)
Data Manipulation Language (DML) include select,update,delete,insert:
•SELECT - Use for retrieving data from a database table •UPDATE – Use for updating data in a database table •DELETE – Use for deletes data from a database table •INSERT - Use for inserts new data into a database table
Syntax
Select * or column1,column2..column n from table_name[where condition];
ExampleSelect * from employee;
Select name from employee;
SELECT STATMENT
INSERT STATMENTSyntax
INSERT INTO table_name[(column1,column2,…)]
VALUES (value1, value2,....) ;
Example;
Insert into emp(id,name,salary)values(101,’Aditya’,100000);
Id Name Sal
1 Aditya 100000
2 Vaidehi 17000
UPDATE STATMENTSyntax
UPDATE table_name
SET column_name = new_value
WHERE column_name = some_value;
Example:
update emp
set salary=50000
where id=101;
Id Name Sal
101 Aditya 50000
102 Vaidehi 17000
DELETE STATMENT
Syntax
DELETE FROM table_name
[WHERE column_name = some_value ]
Example:
delete from employee
where id=101;
Id Name Sal
102 Vaidehi 17000
Thank you!