Академический Документы
Профессиональный Документы
Культура Документы
* SQL
What is SQL?
SQL SQL SQL SQL SQL SQL SQL SQL SQL stands for Structured Query Language allows you to access a database is an ANSI standard computer language can execute queries against a database can retrieve data from a database can insert new records in a database can delete records from a database can update records in a database is easy to learn
Way of procedure to create database and table (database name is vel and table name is murugan): First we have to create database Ex; Create database vel; Then use that database
Ex; Use vel; And then we have to create table Ex; Create table murugan (id int, name varchar (20), city varchar (20)); After create table we have to insert values Ex; Insert into murugan values (1,velmurugan,cuddalore); If we want see that tables then we have to use following queries Ex; Select * from murugan;
Id 1
Name Velmurugan
City cuddalore
If you want to add more than two tables then We should using like following queries Ex; Insert into murugan values (2,balaji,cuddalore), (3,suresh,cuddalore), (4,selvi,chennai), (5,sam, pondy); Then you want see that table Ex; Select*from murugan;
Id 1 2 3 4 5
Select statement: If you want see id no: 2 only means then we have to use Ex; Select id from murugan;
Id 1 2 3 4 5
If you want to see more than two fields, for example consider in name, city field. Then Ex; Select name, city from murugan;
In city field cuddalore comes three times if we want to see the city without difference then we have to use Distinct statement; Ex; Select distinct city from murugan;
Id 1 2 3
Condition cause (<,>, <=,>=, <> (not equal)): If you want to find out less than and more than from numeric field i.e. id then Ex; Select * from murugan where id<3;
Id 1 2
Id 4 5
Id 1 2 3
Id 3 4 5
If we want find out without city=cuddalore then Ex; Select * from murugan where city<>cuddalore;
Id 4 5
Like conditions: If we want to find out the city with first letter then Ex; Select * from murugan where city like c%;
Id 1 2 3 4
Id 2 4
If we want to find out the city with first two letters then Ex; Select * from murugan where city like %cu%;
Id 1 2 3
Insert into statements: If we want insert the datas only for specified columns then Ex; Insert into murugan (id, city) values (7,vadalur); Then Select * from murugan;
Id 1 2 3 4 5 7
Update statment : If we want to update the datas for empty columns then Ex; Update murugan set name=barani where id=7;
Id 1 2 3 4 5 7
If we want update more than one column then Ex; Update murugan set id=6, city=Salem where name=barani;
Id 1 2 3 4 5 6
Delete statment : If we want to delete that particular column from table then Ex; Delete from murugan where id=6;
Id 1 2 3 4 5
If we want to delete overall table then Ex; Delete from murugan; Or Delete * from murugan; Order by clause: If we want to see the name and city in alphabetical order then Ex; Select name, city from murugan order by name, city;
The above format we can use another model like (asc (ascending order), desc (descending order)) Ex; Select name, city from murugan order by name asc, city desc; And or clause: The AND operator displays a row if ALL conditions listed are true. Ex; Select * from murugan where id=3 and city=cuddalore;
Id 3
Name Suresh
City Cuddalore
The OR operator displays a row if ANY of the conditions listed are true. Ex;
Id 1 2 3
You can also combine AND and OR (use parentheses to form complex expressions): Ex; Select * from murugan where (id=3 and city=cuddalore) and id=3;
Id 3 Name Suresh City Cuddalore
In clause: If we want to see that selected datas it can be two or three then Ex; Select * from murugan where name in (balaji,selvi);
Id 2 4
Between .And clause: The BETWEEN ... AND operator selects a range of data between two values. These values can be numbers, text, or dates. Ex; Select * from murugan where id between 2 and 5;
Id Name City
2 3 4 5
Aliases clause: If we want to change the table name and column name then we have to use alias clause If you want change column name then Ex; Select id as userid, name as employeename from murugan;
Userid 1 2 3 4 5 employeename Velmurugan Balaji Suresh Selvi Sam
If you want change the table name of particular column of table then Ex; Select name, city from murugan as balaji;
Name Velmurugan Balaji Suresh Selvi Sam City Cuddalore Cuddalore Cuddalore Chennai pondy