Post on 30-May-2018
8/14/2019 SQL Command Set
1/12
Andhra Loyola InstituteOf
Engineering andTechnology
Mini Project
Submitted to: Sujatha madam
Subject title: Information Technology(C108)
Topic: SQL Command Set
Date: 14-12-2009.
Registered no: 09HP1E0039.
Submitted by:
Md.Rizwan.
MBA-1.
Signature of Lecturer Signature of HOD
8/14/2019 SQL Command Set
2/12
SQL COMMAND SET
SQL statements are divided into categories based on the function that they serve.Some experts consider these categories to be either separate languages or sublanguages .
However, in SQL they all have the basic syntax and rules, so categories of statements withina single language. The categories, each of which is described in a subsequent section, are
Data Definition Language (DDL)
Data Manipulation Language (DML)
Data Control Language (DCL)
Transaction Control Language (TCL) Data Query Language (DQL)
Data Definition Language (DDL)
Data Definition Language (DDL) includes SQL statements that allow the database userto create and modify the structure of database objects, such as tables, views, and indexes.SQL statements that use the commands CREATE, ALTER, and DROPare considered part
ofDDL. It is important to understand that DDL statements affect the containers that hold the
data in the database rather than the data itself. So there are DDL statements to create, drop,and alter tables, but none of these statements provide the ability to create or modify rows of
data in those tables.
CREATE:
Creates a new database object of the type named in the statement. TheCREATE tab TABLE statement is one of the most fundamental in SQL. The relational
paradigm requires all stored data to be anchored in a table, so the ability to storeanything in the database always starts with the creation of a table.
Syntax:
CREATETABLE (column1 data_type (size), column2
data_type (size), . . . . . . . );
8/14/2019 SQL Command Set
3/12
CREATE TABLE statement is really simple. Each statement includes a table nameand a column and comma-separated list of one or more column definitions enclosed in a
pair of parentheses. The table name must be unique with in the database. A table must have
at least one column, which makes logical sense when you think about it.
Example:
CREATETABLE student (sno number(2), sname varchar2(20), JOD date);Table Created.
ALTER:
Oncea table has been created, just about anything that was specified in the CREATE
TABLE statement can be changed using the ALTER TABLE statement. While there isa bit of variation across DBMS implementations, here is a list of the type of changes
usually supported by the ALTER TABLE statement, along with the general syntax for
each type:
Addingacolumn to a table. It is used to add new column to the already existing
table.
Syntax:
ALTERTABLE ADD (new_column_name1 data_type(size), new_column_name2 data_type(size), . . . . . . .);
Example:
ALTERTABLE student add(Fname varchar2(20));
Table altered.
Changing the definition of a column. Most DBMS wont let you decrease columnprecision if there is data in the table, and very few will let you change the data type
of an existing column. Changing unnamed column constraints can be problematic,this is another good reason to name all your constraints.
Syntax:
ALTERTABLE MODIFY (column_name
data_type(size));
8/14/2019 SQL Command Set
4/12
Example:
ALTERTABLE student MODIFY(sno number(10));
Tablealtered.
DROP:
Drops (destroys) an existing database object of the type named in the
statement. It is the simplest of the DDL statement.
Syntax:
DROP TABLE ;
Example:
DROP TABLE student;Table dropped.
Data Manipulation Language (DML):
Data Manipulation Language (DML) includes SQL statements that allow the database
user to add data to the database (in the form of rows in the tables), remove data from thedatabase, and modify existing data in the database.SQL statements that use the commands
INSERT, UPDATE, and DELETE are considered part ofDML.
INSERT:
The INSERT statement in SQL is used to add new rows of data to tables. Itinsert in two basic forms: one where column values are provided in the statement
itself, and the other where values are given bulk by giving back slash (/) .
Single Row Insert Using the VALUES:
The INSERT statement that uses a VALUES can be create only one row each
time it is run because the values for that one row of data are provided in the statement
itself.
8/14/2019 SQL Command Set
5/12
Syntax1:
INSERT into VALUES (value1, value2, . . . . . . .);
Example1:
INSERT into student VALUES (1, abc, 05-25-2005);
1rowcreated.
Note: If the value is of character type specify in single codes ().
Syntax2:
INSERT into (column1, column2, . . . . . . .)VALUES(value1,value2, . . . . .);
Example2:
INSERT into student (sno, sname, JOD) VALUES (1, abc, 05-25-20005);1 row created.
Note: By this we can insert the values of the attributes which we want.
Bulk Row Insert:
The INSERT statement that takes VALUES and create many rows by givingback slash (/) every time and we can enter values.
Syntax:
INSERT into VALUES (&value1, &value2, . . . . . . .);
Note: & accepts n number of values.Example:
INSERT into student VALUES (&sno, &sname, &JOD); 1 row created.
8/14/2019 SQL Command Set
6/12
Note: After entering the query we can observe that by default it will ask thatEnter value for sno:Enter value for sname:Enter value forJOD:
Here we can directly give values. If we want again we can give /
then the previous query will activate.
UPDATE:
The UPDATE statement in SQL is used to update the data values for tablecolumns listed in the statement. Updates existing database table rows.
Syntax:
UPDATE setcolumn_name1=expression[, column_name2=expression, . . . . . . ] [WHERE Clause];
Example:
UPDATE student set sno=85 where sname=abc;
1 row updated.
DELETE:
The DELETE statement removes rows fromatable or database. The DELETE
statement never references any columns because it removes entire rows of data,
including all data values (all columns) for each affected row.
Syntax1:
DELETE from ;
Example1:
DELETE from student;1 row deleted.
8/14/2019 SQL Command Set
7/12
Syntax2:
DELETE from [WHERE Clause];
Example2:
DELETE from student where sname=abc;
1 row deleted.
Data Control Language (DCL)
Data Control Language (DCL) includes SQL statements that allow administrators tocontrol access to the data within the database and the use of various DBMS system privileges,
such as the ability to start up or shut down the database . SQL statements that use the
commands GRANT and ALTERare considered part ofDCL.
GRANT:
The GRANT statement is used to bestow one or more privileges to a database
user.
Syntax:
GRANT privilege [, privilege . . . .] [ON object] TO grantee [, grantee . . .]
[WITH GRANT OPTION];
REVOKE:
Revoking means avoiding the privileges to be granted to particular
user.
Syntax:
REVOKE privilege [, privilege . . . .] [ON object] FROM grantee [, grantee . . .];
8/14/2019 SQL Command Set
8/12
Transaction Control Language (TCL)
TransactionControl Language (TCL) includes SQL statements that stores or retrieve thedata from the database. TCL controls DCL statements. TCL consists of statements
COMMIT, ROLLBACK, and SAVEPOINT
COMMIT:
What ever changes we have done on our table are on all tables those are
saved temporarily.
Syntax:
Commit;
Example:
Commit;
Commitcomplete.
ROLLBACK:
This retrieves last statements that we have done (OR) it acts as an
undo.
Syntax:
Rollback;
Example:
Rollback;
Rollbackcomplete.
SAVEPOINT:
It will save the data up to the point we mentioned. If we dint mention the pointthen it will take by default, by that time we dont know that up to what extent we
saved.
8/14/2019 SQL Command Set
9/12
If we use ROLLBACK then we dont know how many is saved and how many are
deleted.
Syntax:
Save point ;
Example:
Save point ;
Note: is the level name. Up to what level that have to save in the
database, we can give by this.
Data Query Language (DQL)
Data Query Language (DQL) includes SQL statements that retrieve data from thedatabase. Although its a very important part of SQL, DQL consists of statements SELECT
and DUAL.
SELECT:
Tosee particular record in a table (or) whole details of the table . This will
retrieve data from the database.
Syntax1:
SELECT * from ;
Note: To see the fields of the whole table.
Example1:
SELECT * from student;
Sno Sname JOD
1 abc 05-Jan-2005
2 xyz 09-May-2007
8/14/2019 SQL Command Set
10/12
Syntax2:
SELECT * from tab;
Note: To see all the tables in that username.
Example2:
SELECT * from tab;
Syntax3:
SELECT column1, column2, . . . . from ;
Note: To see the particular columns of the table.
Example3:
SELECT sname,sno from student;
Syntax4:
TNAME TABTYPE
BONUS TABLE
DEPT TABLE
EMP TABLE
sname sno
abc 1
xyz 2
8/14/2019 SQL Command Set
11/12
SELECT * from [WHERE Clause];
Note: To see the limited rows of the table up to which we want.
Example4:
SELECT * from student where sname=abc;
Syntax5:
SELECT column1, column2, . . . . from [WHERE Clause];
Note: To see the particular columns of the table.
Example5:
SELECT sname from student where JOD=05-Jan-20005;
DUAL:
It is a workspace used to do some calculations. This is a dummy table
to calculate arithmetic expressions and we get system data from this.
Syntax:
SelectsysdatefromDUAL;
SYSDATE
06-DEC-09
Sno Sname JOD
1 abc 05-Jan-2005
Sname
abc
8/14/2019 SQL Command Set
12/12