Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

SQL Self Notes

Uploaded by

vidhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

SQL Self Notes

Uploaded by

vidhi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DDL DDL DDL DDL DDL DDL DDL DDL DDL DDL DDL

(1) CREATE:

SQL> create table employee

2 (

3 emp_name varchar2(10),

4 gender char(10),

5 sal number(10),

6 DOB date

7 );

Table created.

SQL> desc employee

Name Null? Type

----------------------------------------- -------- ----------------------------

EMP_NAME VARCHAR2(10)

GENDER CHAR(10)

SAL NUMBER(10)

DOB DATE
(2) ALter
(i) Add - to add a colum-ALter table <name> add <new column name> <data type>

SQL> alter table employee add emp_id number(10);

Table altered.

SQL> desc employee;

Name Null? Type

----------------------------------------- -------- ----------------------------

EMP_NAME VARCHAR2(10)

GENDER CHAR(10)

SAL NUMBER(10)

DOB DATE

EMP_ID NUMBER(10)

(ii)
Modify - to change something of the existing data column
SQL> alter table employee modify emp_id varchar2(20);

Table altered.

SQL> desc employee;

Name Null? Type

----------------------------------------- -------- ----------------------------

EMP_NAME VARCHAR2(10)

GENDER CHAR(10)

SAL NUMBER(10)

DOB DATE
EMP_ID VARCHAR2(20)

(iii) rename - to rename a particular thing in the table - alter table <name> rename <what to
rename> <name before> to <name after>

SQL> alter table employee rename column emp_id to employee_id;

Table altered.

SQL> desc employee;

Name Null? Type

----------------------------------------- -------- ----------------------------

EMP_NAME VARCHAR2(10)

GENDER CHAR(10)

SAL NUMBER(10)

DOB DATE

EMPLOYEE_ID VARCHAR2(20)

(iv)
remove - to remove a partcular item - alter table <name> drop <what to drop><name>

SQL> alter table employee drop column employee_id;

Table altered.

SQL> desc employee;

Name Null? Type

----------------------------------------- -------- ----------------------------

EMP_NAME VARCHAR2(10)

GENDER CHAR(10)
SAL NUMBER(10)

DOB DATE

(3) Rename - to rename a table


SQL> alter table employee rename to emp; or rename employee to emp;

Table altered.

SQL> desc emp;

Name Null? Type

----------------------------------------- -------- ----------------------------

EMP_NAME VARCHAR2(10)

GENDER CHAR(10)

SAL NUMBER(10)

DOB DATE

(4) Drop - to drop a table


SQL> drop table emp;

Table dropped.

SQL> desc emp;

ERROR:

ORA-04043: object emp does not exist


(5) truncate - remove all the data i.e all the rows of the table
truncate table <name>

DML DML DML DML DML DML DML DML DML DML
(1) Insert - insert into<table name> values ( line se values, no. without '',date ke prefix mei date likh
the YY-MM-DD)

SQL> insert into employee values('suraj',50000,date'1989-02-20','manager',date'2015-08-15');

1 row created.

to display the table:-

SQL> select * from employee;

EMP_NAME SAL DOB JOB_ROLE HIREDATE

-------------------- ---------- --------- ---------- ---------

suraj 50000 20-FEB-89 manager 15-AUG-15

(2) delete – to delete a row based on some ‘where’ condition.


If no condition entire row will be deleted.

SQL> delete from employee where sal > 50000;

0 rows deleted.

SQL> select * from employee;

EMP_NAME SAL DOB JOB_ROLE HIREDATE


-------------------- ---------- --------- ---------- ---------

suraj 50000 20-FEB-89 manager 15-AUG-15

(3) update -

You might also like