Database Languages
Introduction A DBMS must provide appropriate languages and interfaces for each category of users to express database queries and updates. Database Languages are used to create and maintain database on computer. There are large numbers of database languages like Oracle, MySQL, MS Access, dBase, FoxPro etc.
Introduction SQL statements commonly used in Oracle and MS Access can be categorized as Data Definition Language (DDL) Data Control Language (DCL) Data Manipulation Language (DML).
DDL It is a language that allows the users to define data and their relationship to other types of data. It is mainly used to create files, databases, data dictionary and tables within databases. It is also used to specify the structure of each table, set of associated values with each attribute, integrity constraints, security and authorization information for each table and physical storage structure of each table on disk.
DDL Commands Create Alter Drop
Create Syntax: Example: Create table table_name(attribute1 data type,….attribute n data type); Example: Create table student(id number, name varchar2(10),emailid varchar2(10));
Alter - add Syntax: Example: Alter table table_name add(attribute datatype); Example: Alter table student add(phno number);
Alter- drop Syntax: Example: Alter table table_name drop(attribute); Alter table student drop(phno);
Drop Syntax: Drop table_name; Example: Drop student;
Try to solve..
DML commands Create Select Update Insert Delete
DML commands It is a language that provides a set of operations to support the basic data manipulation operations on the data held in the databases. It allows users to insert, update, delete and retrieve data from the database. The part of DML that involves data retrieval is called a query language.
create SQL > Create Table Cust(cname varchar2(15),cid number(5),caddr char(10), caccno number(5),cacctype varchar2(10),cbalance float, Primarykey(cid),unique(cname),unique(caccno),check(cbalance>=1000)); SQL> desc cust; Name Null? Type ----------------------------------------- -------- ---------------------------- CNAME VARCHAR2(15) CID NOT NULL NUMBER(5) CADDR CHAR(10) CACCNO NUMBER(5) CACCTYPE VARCHAR2(10) CBALANCE FLOAT(126)
select SQL> select * from cust; CNAME CID CADDR CACCNO CACCTYPE CBALANCE --------------- ---------- ---------- ---------- ---------- ----------------------------------- Anusha 1 Chennai 1001 savings 15000 Shriram 2 Pondy 1002 savings 25000 Chamundi 3 Salem 1003 fd 36200 Madhan 4 Salem 1004 checkings 5000 Subha 5 Trichy 1005 checkings 10000 Jayashree 6 Pondy 1006 fd 15000 Sridharan 7 Kanchi 1007 fd 22000 7 rows selected.
update SQL>update cust set caccno=1111 where cname='Chamundi'; 1 row updated SQL> select * from cust; CNAME CID CADDR CACCNO CACCTYPE CBALANCE --------------- ---------- ---------- ---------- ---------- -------------------------------------- Anusha 1 Chennai 1001 savings 15000 Shriram 2 Pondy 1002 savings 25000 Chamundi 3 Salem 1111 fd 36200 Madhan 4 Salem 1004 checkings 5000 4 rows selected.
insert SQL> insert into cust values('Anitha',01,'Chennai',1001,'savings',15000); 1 row created. SQL> insert into cust values('Shriram',02,'Pondy',1002,'savings',25000);
delete SQL>delete from cust where cacctype='fd'; 3 row deleted SQL> select * from cust; CNAME CID CADDR CACCNO CACCTYPE CBALANCE --------------- ---------- ---------- ---------- ---------- ------------------------------------- Anusha 1 Chennai 1001 savings 15000 Shriram 2 Pondy 1002 savings 25000 Madhan 4 Salem 1004 checkings 5000 Subha 5 Trichy 1005 checkings 10000 4 rows selected.
Try to solve…
DCL commands Grant Revoke
DCL Commands DCL statements control access to data and the database using statements such as GRANT and REVOKE. A privilege can either be granted to a User with the help of GRANT statement. The privileges assigned can be SELECT, ALTER, DELETE, EXECUTE, INSERT, INDEX etc. In addition to granting of privileges, you can also revoke (taken back) it by using REVOKE command.
Grant Grant < database_priv [database_priv…..] > to <user_name> identified by <password> [,<password…..]; Grant <object_priv> | All on <object> to <user | public> [ With Grant Option ];
Revoke Revoke <database_priv> from <user [, user ] >; Revoke <object_priv> on <object> from < user | public >;
Try to solve..
Summary In practice, the data definition and data manipulation languages are not two separate languages. Instead they simply form parts of a single database language such as Structured Query Language (SQL). SQL represents combination of DDL and DML, as well as statements for constraints specification and schema evaluation.