Documente Academic
Documente Profesional
Documente Cultură
***********
Alter Session In ORACLE:
========================
To change the system message to english.
alter session set NLS_LANGUAGE='ENGLISH';
The syntax for creating a primary key in an ALTER TABLE statement is:
ALTER TABLE table_name
add CONSTRAINT constraint_name PRIMARY KEY (column1, column2, ... column_n)
ALTER TABLE table_name drop CONSTRAINT constraint_name;
convert function (to_date):
=================
to_date('20120318' || ' 00:00:00', 'YYYYMMDD hh24:mi:ss' )
output:
18-03-2012 0:00:00
Describing a Procedure:
=================
1) desc <procedure name > -- gives u only the in/out parameters used by procedur
e.
2) Select text from user_source where name '<procedure name>'
TO check all DB-LINKS
=================
Q:
select * from DBA_DB_LINKS
ALL_SYNONYM Table:
--------------------------------Name
Null?
------------------------ -------OWNER
NOT NULL
SYNONYM_NAME
NOT NULL
TABLE_OWNER
TABLE_NAME
NOT NULL
DB_LINK
Type
------------VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(30)
VARCHAR2(128)
LAST_UPD
20090704
20090709
20090704
Note: Here , when EVT_ACT_ROW_ID=1 then ,record having LAST_UPD = 20090709 will
be choosen.
--Portugese character problem
================================================================================
=============
If you create a table without the alter session. The default will be 'BYTE'
CREATE TABLE CDM.TEST_SEMANTICS (
RCHAR
VARCHAR2(15) NULL
)
GO
insert into CDM.TEST_SEMANTICS(RCHAR) values ('co')
This one will be ok because there are some spare space.
insert into CDM.TEST_SEMANTICS(RCHAR) values ('cooooooooooooo')
This one not because we are trying to insert the max number of chars for that fi
eld and the will consume a extra char.
This happens because to store the character it is required 2 bytes.
By doing the alter session with the option
=============================================
First set the variable:
export RAY_JARVIS="SybaseEmployee"
Next call isql with the standard parameters:
isql -Uuser -Ppassword -Sservername <<++
-- issue the select command with external variables in where clause
select * from sybase where employee = "$RAY_JARVIS"
go
++
And thats all you need to do.
Reginald Davis , Former Sybase Employee
MultiLine Comment:
===============
(here Document)
----------------------: <<'END'
comments' here
and here
END
SYBASE:
***********
Otherwise, use ALTER DATABASE or
sp_extendsegment to increase size of the segment.
Last time a procedure was executed:
===========================
MDA tables capture information each time a store procedure is run. So if you wri
te a job to poll into a reposiory table monSysStatement where ProcedureID != 0 a
nd object_name(ProcedureID,dbid) with a getdate() appended at the end should do
the trick
TO check which Table a PROXY is pointing to
=================================
select object_type, object_cinfo, char_value
from
sysattributes
where object_type = 'OD' and
object_cinfo = 'ORC_IWS_RECONCILIATION_TABLE'
To insert into sysservers
=========================
insert into sysservers (srvid,srvname,srvclass,srvinfo,srvreadonly)
values ( 1,'DSS2','asejdbc','vfptdwhdev02:4025/ARBOR','N' )
--go to iws_iq sysservers once and check fo ryour server.
TO AVOID DISCONNECT SITUATIONS WHERE PROCEDURE IS UNAWARE
=========================================================
select @SERVER_STATUS = -1
select @SERVER_STATUS = UP
from IQ_PROXY..SERVER_UP
if ( @SERVER_STATUS <> 1956 )
begin
print "ERROR : NO REPLY FROM IWS_IQ...."
return -2
end
RANDOM RECORDS FROM ASE TABLE
===============================
E.g:
select top 10 id, name, r
=
.id=a.id)
from sysobjects a
where name like 'sys%'
order by r
ODSDEV-CONNECTION-STRING:
'vfptodsdev01SS2005.SIEBEL_ODS'
********************************************************************************
********************************************************************************
***************************************
How to find procedures:
**************************
if exists(select 1 from sysprocedure where proc_name = 'ENG_CDR_IN_IMEI_REC' and
user_name(creator) = 'prd')
begin
print 'Dropping procedure prd.ENG_CDR_IN_IMEI_REC...'
drop procedure prd.ENG_CDR_IN_IMEI_REC
end
go
********************************************************************************
********************************************************************************
***************************************
GRANT
======
Q:
GRANT
{ ALL [ PRIVILEGES ]
| ALTER
| DELETE
| INSERT
| REFERENCES [ ( column-name [, ...] ) ]
| SELECT [ ( column-name [, ...] ) ]
| UPDATE [ ( column-name,... ) ]
... ON [ owner.]table-name TO userid [, ...] [ WITH GRANT OPTION ]
Q:
grant execute on <stored_proc> to <(role)or(group)or(userid)>
Check whether a table exists or not
*****************************************
Q:
if exists (select * from sysobjects where id = Object_id('tablename') and type i
n ('U','S'))
EXTRACTING PROCEDURES
======================
Q:
select proc_defn
from sysprocedure
where proc_name= 'ENG_CDR_IN_IMEI'
********************************************************************************
***************************************************
Renaming Procedures:
Q:
sp_rename <old name without db.schema prefix> , <new name without db.schema pref
ix>
or
Q:
alter table [table_name] RENAME [old_column_name] TO [new_column_name]
or
Q:Column Rename
sp_rename "A_SCOV2_USAGE_REVENUE.DW_SERV_ID", DW_ORIG_SERV_ID
or
Q:Table rename
sp_rename A_SCOV2_USAGE_REVENUE , A_SCO_USAGE_REVENUE
********************************************************************************
***************************************************
ALTER COMMAND:
alter table <table name>
eg: (cost was int before)
alter table testbkp
modify <coulmn><datatype>,<coulmn><datatype>
modify COST float
In IQ:
Drop the column and then add, MODIFY does not work
alter table prd.COMMISSIONS_BILLING_DATA delete MOUNT_CREDIT
alter table prd.COMMISSIONS_BILLING_DATA add MOUNT_CREDIT integer
********************************************************************************
***************************************************
IF statement in IQ -> It's different
=============
a)
if @EXTRACOUNT <> 0 then
print 'Inside If';
end if;
b)
if (
@FISCAL_NUM = "111111111"
or
@FISCAL_NUM = "222222222"
@FISCAL_NUM = "888888888"
@FISCAL_NUM = "999999999" )
c)
begin
if exists(select getdate() ) then
print 'YES'
end if
end
d)
begin
if exists(select getdate() )
begin
print 'YES'
print
'yes2'
end
end
FINDING THE user.
or
or
======================================
Q:
select uid,name
from sysusers
where uid in (122,121)
group by uid
Find all objects in a Schema
=====================
Q:
SELECT TYPE,
name,crdate
FROM SYSOBJECTS
WHERE UID IN ( select uid from sysusers
GROUP BY TYPE,name,crdate
ORDER BY TYPE
*
temp_table
base_table
1=0
Create a unique index on the columns that covers the duplicating rows with the
ignore_dup_key attribute. This may be more columns that the key for the table.
create unique index temp_idx
on temp_table(col1, col2, ..., colN)
with ignore_dup_key
Now, insert base_table into temp_table.
insert temp_table
select * from base_table
You probably want to ensure you have a very good backup of the base_table at
this point, coz your going to clear it out! You will also want to check to
ensure that the temp_table includes the rows you need. You also need to ensure
that there are no triggers on the base table (remember to keep a copy!) or RI
constraints. You probably do not want any of these to fire, or if they do, you
are aware of the implications.
********************************************************************************
********************************************************************************
**************************************
========
Convert:
========
select CONVERT(smalldatetime, '20090101', 105)
select convert(timestamp,convert(char(8),getdate(),112) )
--To check
Select cast('2008-09-16' as date) ,convert(date,'16/09/2008',103), date('2008-09
-16')
First day of the month from a given date
=============================
select convert(int,convert(varchar(8),dateadd(dd,-(day(@d)-1),@d),112))
@d-> getdate(),integer,varchar
--sqlserver coversion removing fraction seconds
select to_timestamp('Jan 4 2011 1:17:20:230PM','MON DD YYYY HH12:MI:SS:FF3 AM'
,'nls_date_language = American') from dual
use to_char() if the target column is a character column.
sp_helpdb <>
sp_helpdevice
sp_helpkey <>
sp_helpconstraints <>
********************************************************************************
********************************************************************************
**************************************
Change Password:
=============
sp_password "<OLD-PASSWORD>" , "<NEW-PASSWORD>",<USER-NAME>
sp_iqpassword
********************************************************************************
********************************************************************************
**************************************
Using constraints and alter table
========================
If the index on the table was created using a constraint, follow these steps to
re-create a clustered index:
Drop the constraint:
---------------------------alter table <huge_tab> drop constraint prim_key
Re-create the constraint, thereby re-creating the index:
-----------------------------------------------------------------------------alter table <huge_tab> add constraint prim_key
primary key clustered (key_col)
on <segment>
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|||||||||||
Test from dev:
****************
ssh dwh_app@ptxsa315
AUTOSYS:
Autosys Server from Putty:
*******************************
ptalsun41
uid:pwd: dwh_app
/dwh_app/sched.env /dwh_app/bin/scripts/sched/sched.sh L0SP_UPD_PARAM_CDTRPT SYB
ASE_CONNECTION3 SYBASE_CONNECTION34 DMK N 1
SYBASE_CONNECTION3
Where the Tng table is
SYBASE_CONNECTION34
Where the procedure is
DMK or anything in that position specifies the key word to be attached to the Tn
g table name like Tng_XXXXX_DMK
N
Specifies Not parallel ( but for parallel jobs w
e leave N as it in )
1
The number at this position indicates the CPU to
which this process will be allocated [Values can range from 1-7]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Q:
I am trying to find a query that will return a list of all columns that are part
s of the primary key of a particular table.
output:
select
object_name(sysindexes.id),
sysindexes.indid,
sysindexes.keycnt,
syscolumns.colid,
index_col(object_name(sysindexes.id), sysindexes.indid,
syscolumns.colid)
from sysindexes, syscolumns
where sysindexes.id = syscolumns.id
and syscolumns.colid <= sysindexes.keycnt
and sysindexes.id = object_id('Table1')
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BCP
===
Online tables-BCP is the only option
bcp IWS_DATA_STAGING..ORC_DLT_F_SERVICE_REQUEST out ORC_DLT_F_SERV_REQ.bcp -Ujob
s_diarios -SDSS2 -P$PASSWORD -n -A4096 > $SCHED_LOG_DIR/SRV_REQ/$SCHED_JOB_NAME.
$data
bcp ARBOR..DESCRIPTIONS out DESCRIPTION_EXTRACT.bcp -U KHANS -S DSS2 -P Vodafone
_1600 -c -t '|' -r '^' -A 32768
bcp ARBOR..DESCRIPTIONS in DESCRIPTION_EXTRACT.bcp -U khans -S DSS2 -P Vodafone2
009 -c -t '|' -r '^' -A 32768
IQ tables:
Temporary options is the best options to extract data.
Load command is best to load data.
If u get an error like this:
CTLIB Message: - L0/O0/S0/N0/0/0:
blk_init(): blk layer: CT library error: Cannot find an equivalent CS_TYPE for t
his TDS data type 822083584
blk_init failed.
change column datatype whose data type is date to datetime
Q:
OUTER JOINS
===========
SELECT *
FROM
TableA LEFT JOIN TableB ON Table.col=TableB.col LEFT JOIN
TableC ON TableB.col=TableC.col
SELECT StudentID
FROM lessons
LEFT OUTER JOIN students
ON (lessons.LessonID = students.LessonID AND students.studentID = #studentID#)
================================================================================
===============================================
solution for Cross Server Insert Location problem:
==================================================
When this problem (unable to do "insert into location" inside a prd
owned stored procedure run with another user) arises after a server
restart, you need to do the following:
1) login as prd / Dev@2006
2) create table #a (a int)
3) insert into #a location 'DSS2.IWS' {select 1}
4) logout
This should have been done by the DBAs, so you can always remind them in
the INC itself.
But in case they don't do it, that's the solution.
sp_remotesql
============
--Target Is Iq
exec sp_remotesql "IWS_IQ",@CDC_DELETE_STR, @COMMIT_STR, @CDC_INSERT_STR, @COMMI
T_STR, @D_DELETE_STR, @COMMIT_STR,@D_INSERT_STR,@COMMIT_STR
Syncing IQ data
===============
cd /dwh_app/devdata_transfer/SYNC_DEV/IQ/TABLE SYNC_IQ.sh IWS_IQ prd D_LOYAL_POI
alter database < db_name > log on < logical_device_name > = '100M'
==================================================================
To list all running processes in windows:
>tasklist.exe
To kill any hanged process in windows:
>TASKKILL /F /IM notepad++.exe
--/F for forced
--/IM is image name , Eg- u can give note* to match all the program beginning wi
th that name.