SQL Command Fast Revision

Show The Table

Select * from tab;


Create Table

Create table Table Name (Column Name Data Type (Size), Column Name Data Type (Size));

Ex:- create table student(stu_no number (3), stu_name varchar (25));


Create Table Using Primary Key

Create table Table Name (Column Name Data Type (Size) primary key, Column Name Data Type (Size));

Ex:- create table student(stu_no number (3) primary key, stu_name varchar (25));


Insert a Data Into a Table

Insert into table Name (Column Name, column name) values (Values, values);

Ex:- Insert into student(stu_no, stu_name) values (1, ‘Akash’);

Or

Insert into table Name values (Values, values);

Ex:- Insert into student values (1,’Akash’);


Insert a data with NULL Value

Insert into table name values (value1,value2,NULL,value3);

Ex:- Insert into student values (1,’Akash’,NULL,’50’);


Save a table

Commit;


Show the particular column

Select column name from table name;

Ex:- Select stu_no from student;


Show the all data

Select * from table name;

Ex:- Select * from student;


Update table

Update table name set column where column name=values

Ex:- update student set stu_m1=50 where stu_no=5;


Restore the item

Rollback;


Delete the particular row

Delete from table name where condition;

Ex:- Delete from student where stu_no=3;


Delete all row

Delete from table name;


Show the data with condition

Select * from table name where condition;

Ex:- Select * from student where Stu_no=3;

Select * from table name where column name condition;

Ex:- select * from student where stu_no<3;


Show the addition or multiplication of two or more Column (Arithmetic operator)

Select column name * column name from table name;

Ex:- Select stu_m1* Stu_m2 from Student;

Select column name + column name from table name;

Ex:- Select stu_m1+ Stu_m2 from Student;


Logical Operator

Select * from table name where condition or condition

Ex;- select * from student where stu_no=3 or stu_name=’Akash’;

Select * from table name where condition and condition

Ex;- select * from student where stu_no=3 or stu_name=’Akash’;

Select * from table name where not condition;

Ex;- select * from student where not stu_name=’Akash’;


Special operator

Select * from table name where column name between values and values;

Ex:- select * from student where stu_no between 1 and 3;

Select * from table name where column name is null;

Ex:- select * from student where stu_no is null;

Select * from table name where column name like values (%)

Ex:- select * from student where stu_name like ‘a%’;

Select * from table name where column name like values (_)

Ex:- select * from student where stu_name like ‘a_hi’

select * from table name where column name in (values,values);

Ex:- select * from student where stu_no in(3,4);


alter table

alter table table name modify (column name data type (size));

Ex:- alter table student modify(stu_no number (5));

Alter table table name add(column name data type (size));

Ex:- alter table student add(stu_add varchar (25));

Alter table table name drop column column name;

Ex:- alter table student drop column stu_add;

alter table table name add foreign key (column name) references table;

Ex:- alter table name add foreign key (t_no) references student;

alter table table name add primary key (column name);

Ex:- alter table name add primary key (stu_no)


Drop Table

Drop table table name;

Ex:- drop table student;

Distinct (same data are not show)

Select distinct column name from table name;

Ex:-  select distinct stu_name from student;


Count

Select count(column name) from table name;

Ex:- select count(stu_no) from student;

Select count(stu_no) count from student; (column name is count)

Ex:-select count(stu_no) count from student;


Max and Min

Select max(column name) from table;

Ex:- select max(stu_total) from student;

Select min(column name) from table;

Ex:- select min(stu_total) from student;


Sum

Select sum(column name) as column name from table name     (as column name display in the result)

Ex:- select sum(stu_total) as total from student;


Avg

Select avg(column name) as column name from table name;

Ex:- select avg(stu_total) as avg_stu from student;


Date Data Type

Create table tableName (columnName Date Datatype);

Ex:- create table student (Dob date);


Insert a date in a Table

Insert into tableName values(‘Date’);        Date Formate ’05-Aug-88’

Ex:- insert into student values(’05-agu-88’);


Show the Date or Rang of Date

Ex:- select * from student where dob between ’01-jan-87’ and ’31-dec-88’;

(Show the Result Between this Two Date)


Order By

Select * from TableName orderby ColumnName;

Ex:- select * from student order by dob;

Share

About the Author

Akash Padhiyar

Visit Website

There are no comments yet, add one below.

Leave a Comment

Your email address will not be published. Required fields are marked *

*

Time limit is exhausted. Please reload CAPTCHA.