Saturday, July 30, 2011

Sql Fundamentals Notes


SQL COMMANDS

DDL (DATA DEFINATION LANGUAGE):-

DDL commands are used to create and remove database objects.
The commands are Create, Alter and Drop.

Create Command:-
This command is used to create the table.

Syntax:-create table
(col name datatype(w),col name data type(w));
Example: - create table aparna(sno number(2),name varchar2(10),m1 number(3), m2 number(3));

Rules:
  1. Table name should not be a oracle reserved words.
  2. It is not case sensitive; we can use upper and lower case.
  3. Table name should start with character.
  4. The length of the table name should be below 32 characters.

Alter command:-
This command is used to add a new column and to change the width of the column.

Syntax: - alter
modify/add ;
Example: - alter table aparna add m3 number (3);
Alter table aparna modify name varchar2 (20);

Drop commad:-
This command is used to delete the table.

Syntax: - Drop table
Example: - drop table aparna.


DCL (DATA CONTROL LANGUAGE):-

DCL commands are used to control the kind of data access to the database and also for transaction control.
The commands are Commit, Rollback, Save point.

Commit command:-
This command is used to save the transactions.

Syntax:- commit
Example:-commit

Rollback command:-
This command is used to scroll back the record (previous operations) only DCL commands. This command is exactly opposite of the commit command.

Syntax: - rollback
Example: - rollback.

Savepoint command: -
This command is used to saves the current point in the processing of a transaction. It is just like book mark in ms word.

Syntax: - savepoint

DML (DATA MANIPULATE LANGUAGE):-

DML commands are used for data manipulation.
The commands are Select, Insert, Update and Delete.

Select command: -
This command is used to retrieve the row from the database files.

Syntax: - select * from
Example:- select * from rama.

Insert command:-
This command is used to insert records in to the table.

Syntax: - insert into
values
Example: - insert into rama (sno, name, m1, m2, m3) values (&sno,’&name’, &m1,&m 2, &m 3);

Update command:-
This command is used to update the database records

Syntax: - update
set =number;
Example: - update emp set comm=sal*100;

Delete command:-
This command is used to delete the records from the data base.

Syntax: -delete from
where
Example: - delete from emp where sal>=500;

Note: - where clause is used to give conditions.

TCL (TRANCTION CONTROL LANGUAGE)

TCL commands are Grant and Invoke.

Grant command: -
This command is used to give access to the database that to grant permissions for the DML, DCL commands

Revoke command:-
This command is used to get back the given grant permission.


OTHER STANDARD COMMANDS:-

  1. Select * from tab;
This sql statement is used to get the list of tables.

  1. Select * from tab;
This command is used to view the information of the current user.


  1. Desc command:-

This command is used to display the structure of the table.

Syntax: - desc table name;
Example: - desc table rama;

These two Exercise can be easily done by practicing the above all commands

Exercise-25
Execute any six Sql commands
Exercise-26
Design a database in Sql for the sale receipt of medicines with the following columns:-
Sno, Name of the product, Quantity, cost. Enter 5 different medicines and display the reports



No comments:

Post a Comment