Skip to main content

Posts

Showing posts from August, 2013

Know that Truncate is DML or DDL in SQL

These are some reason why truncate is ddl not dml 1. TRUNCATE can change storage parameters (the NEXT parameter), and those are part of the object definition - that's in the DDL commands. ... 2. TRUNCATE does an implicit commit, and cannot be rolled back most DDL operations in Oracle do this, no DML does.that's Truncate is DDL 3. TRUNCATE TABLE handles table as an entity to clear all data from the specified table 4. Deallocates all space used by the removed rows make truncate to DDL 5. The fact that TRUNCATE doesn't run ON DELETE triggers also sets it apart from normal DML operations (but some DML operations also skip triggers, so that's not a clear indicator. As TRUNCATE removes all rows, it can theoretically be implemented by dropping the table and recreating it in which case it is like any other DDL statement The statement is not expected to be used for usual transactions where insert,update,delete and select statements are used.It is mainly meant for

Example of rollup and cube in sql

SQL> SELECT DEPTNO,SUM(SAL)  2 FROM EMP  3 GROUP BY ROLLUP(DEPTNO)  4 /  DEPTNO SUM(SAL) ---------- ----------  10 8750  20 10875  30 9400  29025 SQL> ED Wrote file afiedt.buf  1 SELECT NVL(TO_CHAR(DEPTNO),'TOTAL'),SUM(SAL)  2 FROM EMP  3* GROUP BY ROLLUP(DEPTNO) SQL> / NVL(TO_CHAR(DEPTNO),'TOTAL') SUM(SAL) ---------------------------------------- ---------- 10 8750 20 10875 30 9400 TOTAL 29025 SQL> ED Wrote file afiedt.buf  1 SELECT NVL(TO_CHAR(DEPTNO),'TOTAL'),SUM(SAL)  2 FROM EMP  3* GROUP BY CUBE(DEPTNO) SQL> / NVL(TO_CHAR(DEPTNO),'TOTAL') SUM(SAL) ---------------------------------------- ---------- TOTAL 29025 10 8750 20 10875 30 9400 SQL> ED Wrote file afiedt.buf  1 SELECT NVL(TO_CHAR(DEPTNO),'TOTAL'),JOB,SUM(SAL)  2 FROM EMP  3* GROUP BY ROLLUP(DEPTNO,JOB) SQL> / NVL(TO_CHAR(DEPTNO),'TOTAL') JOB SUM(SAL) ---------------------------------------- --------- ---------- 10 CLERK 1300 10 MANAGER 2450 10 PR