- It is a language used to access data within oracle database.
- Developed by IBM in mid 1970’s.
- Oracle corporation introduced the first commercially available implementation of SQL.
- It is pronounced as ‘sequel’ and SQL stands for Structure Query Language.
- It is English like language and also have nested environment to ease queering , the classification of SQL commands are
DDL (Data Definition Language)
DML (Data Manipulation Language)
DCL (Data Control Language)
TCL (Transaction Control Language)
Data Type :Type of a data stored in a column.
1.char(size) : Fixed-length character data,size character long,Maximum size is 2000.
2.varchar2(size) : Variable length character string have maximum size of 4000 bytes.
3. Number(size) : stores fixed and floating point numbers.
4. Date : stores date and time.
5. Long : can store up to 2GB of characters.
6. Raw : store graphics,sounds,etc..
7. Longraw : contains raw binary data.
useful commands :
1) cl scr: Clear the screen
2) to_char : to_char function is used to convert oracle date format (dd-mon-yy) into user required date format
select to_char(<filedname>,’dd-mm-yyyy hh:mm:ss’) from <tablename> ;
select to_char(edoj,’dd-mm-yyyy hh:mm:ss’)date_time from emp;
3) linesize : default size is 80 we can change by using this linesize function
sql>set linesize 120;
4) dual : It is a table that is automatically created by Oracle Database along with the data dictionary.
DUAL is in the schema of the user SYS but is accessible by the name DUAL to all users.
It has one column, DUMMY, defined to be VARCHAR2(1), and contains one row with a value X.
sql>desc dual;
sql>select * from dual;
sql>select sysdate from dual;
Classification of SQL Commands :
1. Data
Definition Language (DDL)
DROP
RENAME
CREATE
ALTER
TRUNCATE
2. Data
Manipulation Language (DML)
SELECT
INSERT
UPDATE
DELETE
3. Data
Control Language (DCL)
GRANT
REVOKE
SET
ROLE
4. Transaction
Control Language (TCL)
COMMIT
ROLL
BACK
SAVE
POINT
1.Data Definition Language(DDL):DROP,RENAME,CREATE,ALTER,TRUNCATE are called DDL(data definition language)commands. They are called data definition since they are used for defining the data that is the structure of the data is known through DDL commands.
Drop:
DROP command completely removes a table from the database. This command will also
destroy the table structure and the data stored in it.
Syntax:
DROP TABLE <TABLE NAME>; Example: DROP TABLE PRODUCT;
DROP command completely removes a table from the database. This command will also destroy the table structure and the data stored in it.
stdadd varchar2(10),
phno number(10));
stdno number(5)
stdname varchar2(10)
stdadd varchar2(10)
phno number(10)
How To Create A New User:
1.C:\Users\Admin>sqlplus / as sysdba
2.SQL> show user;
USER is "SYS"
3.SQL> create user rkdbms identified by rkdbms123;
4.SQL> conn rkdbms; // we will get error
SQL> conn rkdbms;
Enter password:
ERROR:
Warning: You are no longer connected to ORACLE.
ORA-01045: user RKDBMS lacks CREATE SESSION privilege; logon denied
5.from sql prompt we can connect to sys
SQL> conn / as sysdba
6.SQL> grant connect to rkdbms;
7.SQL> grant resource to rkdbms;
8.conn rkdbms
enter the password
Now the user rkdbms is ready to use.
CREATE USER <USER NAME>
Note3: Now user “RKDBMS” is ready to use
ALTER : Alters the structure of the data base
Alter : ADD
Syntax:
ALTER TABLE <TABLE NAME> ADD(COUMNNAME DATATYPE(SIZE));Alter : RENAME
Truncate:
Syntax:
TRUNCATE TABLE <TABLE NAME>
Update:
Delete:
LIKE:
There are two wildcards used in conjunction with the LIKE operator.
1. The percent sign (%)
The percent sign represents zero, one or multiple characters.
2. The underscore (_)
The underscore represents a single number or character.
These symbols can be used in combinations.
3. Data Control Language(DCL):
Data control language are the commands to grant and take back authority from any database user.
We can grant users various privileges to tables.
Ex:If we want to grant SELECT, INSERT, UPDATE, and DELETE privileges on a table called product to a user name rkdb, the command would be:
GRANT SELECT, INSERT, UPDATE, DELETE ON product TO rkdb;
We can also use ALL keyword to indicate that you wish ALL permissions to be granted for a user named rkdb
GRANT ALL ON product TO rkdb;
If we want to grant only SELECT access on your table to all users, you could grant the privileges to the public keyword. For example:
GRANT SELECT ON product TO public;
Revoke Privileges
We can revoke any combination of SELECT, INSERT, UPDATE, DELETE, REFERENCES, ALTER, INDEX, or ALL.
REVOKE privileges ON object FROM user;
If we want to revoke DELETE privilege on a table called product from a
user named rkdb:
REVOKE DELETE ON product FROM rkdb;
If we had granted ALL privileges to public (all users) on the product table and you wanted to revoke these privileges:
REVOKE ALL ON product FROM public;
SCHEMA 2 : EMPLOYEE
1)Create a table employee with attributes eid,ename and sal.
2)add a new column email to employee table.
3)change the size of eid as 5
4)add
a new column city
5)change the data type of ename
as char
6)add a new column dept
7)change the city column name as PLACE
8)remove the column dept
9)add a new column dob.
11)display table structure
12)display all the records in the table - without
and with condition. 13display employee name and age of all employees.
14)display employee id ,age and salary of all employees whose name
starts with 's'
15)modify all records in employee table by giving
1500 hike in their salary.
16)display all records.
18)remove all records
in table - delete
19)display the structure
20)restore
deleted records
21)display all records
22)remove all records - truncate
23)change employee
table name as emp.
24)add
a new column email to employee
table.
No comments:
Post a Comment