Showing posts with label best practices. Show all posts
Showing posts with label best practices. Show all posts

Wednesday, February 8, 2012

Disable "Save Password" in SQL Developer

Handy information for people who connect to various databases, yet share their workstations. You may have SQL Developer where you tend to store passwords, and to prevent accidental connection to your databases when others use the machine, it is safe to disable the "Save password" option on your SQL Developer.

Edit the sqldeveloper/bin/sqldeveloper.conf and add this:
AddVMOption -Dsqldev.savepasswd=false



Wednesday, April 7, 2010

Hierarchical queries (or recursive queries) in SQL Server 2005/2008

The question is ... how do you run hierarchical queries in SQL server ? I was trying to find something similar to CONNECT BY..PRIOR clause in Oracle. We stepped in to CTE (Common Table Expression). Awesome feature !

* Table has two columns... emp_id, mgr_id (LEVEL in the query is a computed column)

WITH DirectReports (MGR_ID, EMP_ID, Level)
AS
(
-- Anchor member definition
    SELECT mgr_id, emp_id, 0 AS Level
FROM test_emp_mgr    
    WHERE mgr_id is null


    UNION ALL
-- Recursive member definition
    SELECT e.mgr_id, e.emp_id,Level + 1
    FROM test_emp_mgr AS e
    
    INNER JOIN DirectReports AS d
        ON e.mgr_id = d.emp_id
)
-- Statement that executes the CTE
SELECT *
FROM DirectReports;

Monday, December 21, 2009

BULK UPDATE using FORALL in Oracle PLSQL - Awesome experience..

In one of the projects I work, there arose a need to conditionally update a few column values of a table. How many rows did we need to update ? Roughly 5 million rows out of 252 million total rows.

Experimented many approaches to get this done. Some of them ....
1. Use a single UPDATE statement (Worst thing to ever do for huge data updates)
2. Update in lots of 50K - using plain update statement (Kind of OK, though it handled shorter commits, I wasnt happy with performance)
3. Fantastic result : When I used PLSQL(bulk update using FORALL), I realized I had been under utilizing PLSQL for my day to day jobs. No doubt... Oracle PLSQL rocks.