Sei sulla pagina 1di 7

INTRODUCTION TO SQL

SQL is ANSI standard computer language for Relational Database Management Systems such as Oracle, Sybase, Microsoft SQL Server, Access, Ingress etc. It is an industry standard language for creating, updating and querying relational database management systems. SQL, which talks to a relational database, is a language about manipulating sets of data stored in tables. It consists of relatively small number of main commands such Create, Alter, Drop, Select, Insert, Update etc to accomplish this.SQL has a special version named PL/SQL, which is sometimes termed as a superset of SQL. It bridges the gap between database technology and procedural languages as programmers can use PL/SQL to create programs for validation and manipulation of table, something that was not possible with SQL. While SQL, also called Interactive SQL, is used to create maintain tables, indexes etc. and also for data manipulation interactively, PL/SQL is used to create programs for validation and manipulation of table data. PL/SQL is thus a language closely related to SQL but allows you to write programs as ordered series of statements. In this section we will explain some of the basic terminologies which will be required to learn SQL. We will give an overview of what SQL is and what does it do etc. Runs queries against a database. Retrieves data from database. Inserts new records into a database. Updates records in a database. Deletes records from a database. Creates/deletes tables in a database. Alters the table structure in a database. Is easy to learn and understand. SQL DATABASE TABLES As explained above, database is nothing but a collection of inter-related tables. A table consists of rows and columns. Rows are the records stored whereas columns are attributes or fields. Each table is identified with a name e.g, Employee (Emp_id, Emp_name, Age, Salary), suggesting Table named Employee has four fields-Emp_id, Emp_name, Age, Salary

FOLLOWING LANGUAGES COVER THE SQL FUNDAMENTAL:

1. Data Definition Language (DDL): It defines data and their relationship with other types of data to users. It is mainly used in creating database, files, data dictionary and tables. Examples: Create, alter, drop, rename 2. Data Manipulation Language (DML): It provides set of operations on the data held in the databases. Examples: Delete, insert, select, update 3. Data Control Language (DCL): It controls the access to the data and the database using statements such as follows: Examples: Grant, revoke, comment 4. Transaction Control Language (TCL): It manages the changes made by the DML statements. Examples: Commit, rollback, savepoint, settransaction 5. Embedded SQL Statements: These are used to incorporate DDL, DML and TCL statements within the body of the procedural language program. Examples: i. define:- defines cursor ii. open:- allocates the cursor iii. declare:- assigns variable names iv. execute:- execute SQL commands v. fetch:- retrieve data from database http://www.sharemca.com/download-data-base-management-system-dbms-sql-notes.php

What are the difference between DDL, DML and DCL commands?
Submitted by admin on Wed, 2004-08-04 13:49

DDL
Data Definition Language (DDL) statements are used to define the database structure or schema. Some examples:

o o o o o o

CREATE - to create objects in the database ALTER - alters the structure of the database DROP - delete objects from the database TRUNCATE - remove all records from a table, including all spaces allocated for the records are removed COMMENT - add comments to the data dictionary RENAME - rename an object

DML
Data Manipulation Language (DML) statements are used for managing data within schema objects. Some examples:

o o o o o o o o

SELECT - retrieve data from the a database INSERT - insert data into a table UPDATE - updates existing data within a table DELETE - deletes all records from a table, the space for the records remain MERGE - UPSERT operation (insert or update) CALL - call a PL/SQL or Java subprogram EXPLAIN PLAN - explain access path to data LOCK TABLE - control concurrency

DCL
Data Control Language (DCL) statements. Some examples:

o o

GRANT - gives user's access privileges to database REVOKE - withdraw access privileges given with the GRANT command

TCL
Transaction Control (TCL) statements are used to manage the changes made by DML statements. It allows statements to be grouped together into logical transactions.

o o o o

COMMIT - save work done SAVEPOINT - identify a point in a transaction to which you can later roll back ROLLBACK - restore database to original since the last COMMIT SET TRANSACTION - Change transaction options like isolation level and what rollback segment to use

Command
Command: Create Purpose: This command is used to create tables. Syntax: Create table <table name> (column 1 data type<size>, column 2 data type <size>); Example:: SQL> create table student2(s_no varchar2(4), name char(15), roll_no varchar2(6), branch char(10)); Command: Desc Purpose: This command is used to describe table. Syntax: desc <table name>; Example:: SQL> desc student2; Name Null? Type Command: Insert Purpose: This command inserts values in the table. Syntax: Insert into table name (col name 1, column name 2) values (value1, value2); Example:: SQL> insert into student2 values (1,'AMAN', 7213,'c.s.e.'); SQL> insert into student2 values (2,'ANKIT, 7216,'c.s.e.'); SQL> insert into student2 (s_no,name,branch) values(3,' ADITYA',7206,'c.s.e.'); Command: Select Purpose: Selects all columns and rows from table,* and distinct are the options used with it. Syntax: Select [distinct] <tablename.columnname> From<tablename>

[Where <condition>] [Group by<columnname(s)>] [Having <condition>] [Order by <expression>]; Example:: SQL> select * from student2; SQL> select * from student2 where name='ANKIT'; SQL> select * from student2 where s_no=3; Command: Alter Purpose: This is used to modify the structure of the table. Syntax: Alter table name add<new column datatype<size>; Example:: SQL> alter table student2 add( address varchar2(25)); SQL> select * from student2; SQL> alter table student2 modify( address varchar(28)); SQL> alter table student2 drop(address); SQL> select * from student2; Command: Delete Purpose: This command is used to delete all the rows or either a set of rows from a table. Syntax: Delete from <table name>; Delete from <table name> where <condition>; Example:: SQL> delete from student2 where name='purneet'; SQL> select * from student2;

SQL> delete from student2; SQL> select * from student2; Command: Update Purpose: This command is used to change and modify the data values in a table. Syntax:Update <table name>set<column name1>=<expresson1>, < column name2>=<expresson2>; Example:: SQL> update student2 set name='AKSHAY' where s_no=3; SQL> select * from student2; Command: Rename Purpose: This command is used to rename a table. Syntax: Rename<table name> to <new table name>; Example:: SQL>rename student2 to student; SQL> select * from student; Command: Order by command Purpose: The ORDER BY clause sorts the result set based on the columns specified. Syntax: Order by<column name1>, <column name2> <[sort order]>; Example:: SQL> select * from student2 order by roll_no asc; SQL> select * from student2 order by s_no asc; SQL> select * from student2 order by s_no desc;

Command: Drop Purpose: This command is used to destroy a table. Syntax: Drop table <table name>; Example:: SQL> drop table student2; SQL> select * from student2;

Potrebbero piacerti anche