Monday, February 21, 2011

The easy way to Get table and index DDL script

The easy way to Get table and index DDL script: The dbms_metadata utility helps to display DDL directly from the data dictionary. We see the small example. Initial setup:SQL> conn scott/tiger;Connected.SQL> create table GET_TAB_SCRIPT2 (3 c1 varchar2(10),4 c2 number5 );Table created.SQL> insert into get_tab_script values ('A',10);1 row created.SQL> commit;Commit complete.SQL> create index idx_1 on GET_TAB_SCRIPT (c1);Index created. To get table script: SQL> select dbms_metadata.get_ddl('TABLE','GET_TAB_SCRIPT') from dual;DBMS_METADATA.GET_DDL('TABLE','GET_TAB_SCRIPT')------------------------------------------------CREATE...

Saturday, February 12, 2011

Order by based on the parameter passed in SQL server:

Order by based on the parameter passed in SQL server:Dynamically ordering a result set based on the parameter passed is a powerful technique for ordering your data. The below example shows that and see the issues which we faces.Initial setup:create table dept(deptid int,deptname varchar(10))insert into dept values (1,'Sales')insert into dept values (4,'Production')insert into dept values (3,'fiance')insert into dept values (2,'HR')The following SQL script shows how you might try to use a CASE expression to dynamically order a result set:DECLARE...