Professional Documents
Culture Documents
Statements
Ex. No : 04
Date :
To create a new table with the set of columns specified with respective types.
2. INSERT Statement:
3. UPDATE Statement:
UPDATE table
SET column = value [, column = value]
[WHERE condition];
4. DELETE Statement:
The data dictionary tables can be queried to view various database objects owned by
the user. Frequently used dictionary tables are:
7. RENAME Statement:
8. TRUNCATE Statement:
9. COMMENT Statement:
Comments stored in the data dictionary can be viewed in one of the following data dictionary
views in the COMMENTS column:
1 row created.
SQL> select * from dept;
1 row created.
6 rows selected.
8 rows selected.
Adding new employee record to the Employee ‘EMP’ table using SYSDATE and
USER.
SYSDATE and USER function records the current date and time.
1 row created.
1 row created.
2 rows selected.
1 row created.
5 rows selected.
3 rows selected.
3 rows created.
3 rows selected.
4 rows updated.
4 rows selected.
4 rows selected.
Specific row or rows are deleted when you specify the WHERE clause.
4 rows selected.
`
SQL> DELETE FROM DEPT2;
4 rows deleted.
DATABASE TRANSACTIONS:
After the end of a transaction, the next executable SQL statement will
automatically start the next transaction. A DDL statement or a DCL statement is
automatically committed and therefore implicitly ends a transaction.
Q: 9 - Committing data:
1 row updated.
Commit the changes made to the EMP table so that all changes are made permanent.
SQL> COMMIT;
Commit complete.
4 rows deleted.
No rows selected.
SQL> ROLLBACK;
Rollback complete.
4 rows selected.
2. Make a save-point so that the state of data in the database can be restored to this point,
later.
Savepoint created.
1 row created.
5 rows selected.
Rollback complete.
Q: 12 – Creating tables.
SQL>CREATE TABLE DEP (DEPTNO NUMBER (2), DNAME VARCHAR2 (14), LOC
VARCHAR2 (13));
Table created.
SQL>DESC DEP;
OBJECT_TYPE
------------
INDEX
TABLE
TABLE_NAME TABLE_TYPE
------------------------------ -----------
DEP TABLE
DEPT2 TABLE
DEPT3 TABLE
DEPT5 TABLE
EMP TABLE
EMP2 TABLE
EMP3 TABLE
EMP4 TABLE
MANAGERS TABLE
9 rows selected.
Table created.
SQL>DESC DEPT30;
ALTERING A TABLE:
Q: 15 – Adding a column.
Table altered.
SQL>DESC DEPT30;
Q: 16 – Modifying a column.
Table altered.
SQL>DESC DEPT30;
Table altered.
Q: 18 – Dropping a Table.
Table dropped.
Q: 19 – Renaming an object.
Table renamed.
Q: 20 – Truncating a Table.
Table truncated.
No rows selected.
Comment created.
CONSTRAINTS:
Table created.
Table created.
Table created.
Table created.
Q: 25 – Adding a constraint.
Table altered.
CONSTRAINT_NAME C SEARCH_CONDITION
------------------------------ - -----------------------------------------------------------------------
EMP_EMPNO_PK P
Table altered.
Q: 26 – Dropping a constraint.
Q: 27 – Disabling a constraint.
Constraint disabled.
Q: 28 – Enabling a constraint.
Constraint enabled.
Q: 29 – Viewing constraints.
CONSTRAINT_NAME C SEARCH_CONDITION
------------------------------ - ----------------------
SYS_C003010 C "ENAME" IS NOT NULL
SYS_C003011 C "DEPTNO" IS NOT NULL
EMP_DEPTNO_FK R
CONSTRAINT_NAME COLUMN_NAME
-------------------------------------------------------
EMP_DEPTNO_FK DEPTNO
SYS_C003010 ENAME
SYS_C003011 DEPTNO
SHASHIKIRAN V., ASSISTANT PROFESSOR (SENIOR), SITE, VIT VELLORE.
DDL AND DML
Statements
VIEWS
Q: 30 – Creating a view.
View created.
SQL>DESC EMPVU10;
Q: 33 – Modifying a view.
SQL>desc empvu10;
EMPLOYEE_NUMBER EMPLOYEE_NAME JOB_TITLE
---------------------------------------------------------
7196 Smith salesman
7197 John rep
7799 James manager
View created.
SQL>desc dept_sum_vu;
Name Null? Type
-------------------------------------------------
VARCHAR2(14)
MINSAL NUMBER
MAXSAL NUMBER
AVGSAL NUMBER
SQL>desc empvu20;
Name Null? Type
-------------------------------------------------
EMPNO NUMBER(4)
ENAME VARCHAR2(20)
JOB VARCHAR2(15)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(5)
COMM NUMBER(4)
DEPTNO NUMBER(2)
View created.
SQL>desc empvu10;
View dropped.
SQL>desc EMPVU10;