Skip to main content

Posts

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) ---------------------------------------- --------- ----------...

Ways to Tune the Queries in SQL and Type of Indexes

There are many methods to tune up a query. 1) using EXPLAIN_PLAN. 2) using AUTOTRACE and set Timing ON. 3) tkprof 4) Indexes 5) Cost- based Optimisation 6) Analyze command. 7) parallel query option. Types of indexes B-tree Bitmap Hash Index-organized table Reverse key Function-based Partitioned (local and global) Bitmap join indexes

Difference in length between the first biggest and the second biggest name in sql table

to get difference in length between the first biggest and the second biggest name in SQL table like Employees table. You can try following query to get the same. 1. SELECT MAX(DECODE(DR, 1, L, NULL)) - MAX(DECODE(DR, 2, L, NULL)) AS DIFF FROM ( SELECT LENGTH(FIRST_NAME||LAST_NAME) AS L, DENSE_RANK() OVER(ORDER BY LENGTH(FIRST_NAME||LAST_NAME) DESC) AS DR FROM EMPLOYEES ) WHERE DR IN (1, 2) 2.select max(a) - min(a)from ( select distinct(length(FIRST_NAME)) a from EMPLOYEES order by length(FIRST_NAME) desc) where rownum < 3

How to copy dvd files and folder's to your folder using Command Prompt

How to copy dvd files and folder's to your folder using Command Prompt To copy a single file-->copy source destination for example :- copy D:\ts\steps.txt E:\Newfolder To copy multiple files-->copy source1 source2 destination for example :- copy D:\t\test.txt D:\t\avx.txt E:\Newfolder You can also use robocopy command more!.. make like robocopy (source file) (destination file) copy options and file to copy.. Eg: (in dvd in partition D:) robocopy D:\ C:\users\user_name\desktop\newfolder /s * This command will copy everything in D:\ (which is the dvd drive) to your desktop folder named new folder and /s means it will copy all sub directories except empty ones .. then the * means all files in the D:\ partition!...

Right approach to use join for particular scenario in sql

I have a table that looks like this: CREATE TABLE #C (grpType varchar(10), CPTCode varchar(10) NULL, Month int NULL, MTD money NULL, MonthCount int NULL, YTD money NULL, YearCount int NULL, Code varchar(10) NULL) It has the following data in it: grpType CPTCode Month MTD MonthCount YTD YearCount Code Month 76800 5 1321.61 27 6574.54 82 76800 Month 76856 5 246.01 3 380.64 6 76856 Month 76881 5 9778.95 131 50682.59 509 76881 Month 76942 5 22467.33 190 116663.58 674 76942 Then I have another table: CREATE TABLE #Prod (grpType varchar(10), TotalCharges money NULL, TotalUnits float NULL, RVU float NULL, Code varchar(10) NULL, CPTCode varchar(10) NULL) This table has the following data in it: grpType TotalCharges TotalUnits RVU Code CPTCode Month 6100.00 12 0 76800 76800 Month -475.00 -1 0 76880 76880 Mont...

What is OLAP

OLAP is an acronym for On Line Analytical Processing, and it is becoming the fundamental foundation for Intelligent Solutions including Business Performance Management, Planning, Budgeting, Forecasting, Financial Reporting, Analysis, Simulation Models, Knowledge Discovery, and Data Warehouse Reporting. OLAP performs multidimensional analysis of enterprise data and provides the capabilities for complex calculations, trend analysis and very sophisticated data modeling. OLAP enables end-users to perform ad hoc analysis of data in multiple dimensions, thereby providing the insight and understanding they need for better decision making.