Common SQL Commands

SQL commands are divided into categories like DML (Data Manipulation language), DDL (Data definition language), TCL (Tranction control language) and DCL (Data control language).


 

Ads

Tutorials   
JDBC Video Tutorial: Create, Read, Update and Delete (CRUD) Operation examples JDBC Video tutorial - How to read Data from MySQL Database? JDBC Video tutorial - How to delete Data in a MySQL Database? Solving java.lang.ClassNotFoundException: com.mysql.jdbc.Driver exception JDBC Video tutorial - How to update Data in a MySQL Database? JDBC Video Tutorial- How to insert data into MySQL database table? JDBC Video Tutorial: How to download JDBC Driver for MySQL? JDBC Tutorial - Writing first JDBC example and running in Eclipse Java Cross Join MySQL Database Connectivity Example In Java Change Column Name in MySQL Java Mysql Connection Example JDBC ODBC Connection In Java ResultSet In Java Prepared Statement Example JdbcRowSet interface Java JdbcRowSet Example First Step towards JDBC! JDBC Training, Learn JDBC yourself Jdbc Get Column Names JDBC Example with MySQL JDBC Prepared Statement Update JDBC Prepared Statement Insert JDBC Prepared Statement Example JDBC Prepared statement Close JDBC Prepared Statement Addbatch JDBC Nested Resultset JDBC-Odbc Connection JDBC-Odbc Connectivity JDBC Insert Preparedstatement JDBC Insert Null JDBC Get Metadata JDBC Insert Record Jdbc Insert Statement JDBC Meta Data Get tables Jdbc Mysql Connection String Jdbc Mysql Connection Url JDBC Next Jdbc Get Connection JDBC Get Int JDBC Exception JDBC Get Row Count JDBC Functions JDBC Fetch JDBC Execute Update Example JDBC Execute Statement JDBC Execute Query JDBC Drive For Mysql JDBC Connectivity Code In Java JDBC connection timeout
Ads

Common SQL Commands

  

SQL commands are divided into categories like DML (Data Manipulation language), DDL (Data definition language), TCL (Tranction control language) and DCL (Data control language). Here are a list of SQL commands.

1. DML COMMANDS

INSERT
UPDATE
SELECT
DELETE

2.DDL COMMANDS
CREATE
ALTER
DROP

3.TCL COMMANDS
COMMIT
ROLLBACK

4.DCL COMMANDS
GRANT
REVOKE

The table given below (named Student) has two fields id and Name.

Student Table

id

Name

1

Ravi

2

Ajay

 The commands are based on this table:

1. DML COMMANDS

INSERT ROWS
The syntax for this command is

insert into tablename(colname1,colname2) values(value1,value2);

Example:

insert into Student (id, Name) values(1,'Ravi');

This statement is used to insert a row of data into Student table.

UPDATE ROWS
The syntax for this command is

update tablename set colname1=colvalue where colname2=colvalue;

Example:

update Student set Name = 'Ajay' where id = 2;

This command has updated the Name 'Rose' in Student table whose id is 2.

SELECT ROWS
This command is used to select rows from a table.The syntax for this command is

select colname1,colname2 from tablename;

Example:

select Name from Student;

It will display all names from Student table. Like Ravi.

DELETE ROWS
The syntax for this command is-

delete from tablename where [search_conditions];

Example:

delete from Student where id=1;

This statement is used to delete the row from Student table where the student id is 1.

2. DDL COMMANDS

CREATE TABLE
This statement is used to create a table. The syntax for this command is

create table tablename (colname1 datatype [constraint], colname2 datatype [constraint]);

Example:

create table Student (id number(4) primary key, Name varchar2(20));

It creates the table Student which has two fields id i.e. Student id and Name i.e. the student name. The number and varchar2 are the data types of id and Name respectively. Field 'id' has the size 4 means it can take id up to 4 digits and same for Name, it can take the size up to 20 characters. And also added the constraint Primary key to the field 'id'.

ALTER TABLE
This command is used to add, drop columns in a table. The syntax for this command is

alter table tablename add colname1 datatype [constraint];
alter table tablename drop column colname1;

Example:

alter table Student add DOB date;

This command is used to add new field DOB in Student table. It's datatype is date. This is also used for drop column from the table. It will drop the DOB field by query given below-

Alter table Student drop column DOB;

DROP TABLE
The syntax for this command is-

drop table tablename;

Example:

drop table Student;

This statement is used for destroy the table from database.

3.TCL COMMANDS

COMMIT
This command is used for save the work done. The syntax is:

COMMIT;

ROLLBACK
This command is used to restore the database to original since the last commit. The syntax is-

ROLLBACK;

4. DCL COMMANDS

GRANT
This command is used for gives access privileges to users for database. The syntax is-

GRANT dba to username;

REVOKE
This command is used for withdraws access privileges to users for database. The syntax is-

REVOKE permissions on tablename from username;


Advertisements

Ads
Share on Google+Share on Google+

Common SQL Commands

Posted on: June 27, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

 

Discuss: Common SQL Commands   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:5
sathish kumar
June 23, 2011
structered query language

good
dhivya
February 19, 2013
why we use foreign key?

nice
Divya
March 10, 2012
SQL Commands

Too Good...
RENEE
March 19, 2012
SQL COMMANDS

Thanks to this site it was very helpful to me.Because I will be doing an sql test later and this site has teach me a lot of commands i didn't know.thanks again and continue to keep up the good work.
Rajnish Singh
October 9, 2012
sql commands

It is quite good..

Ads

 

Ads