T-SQL – Check if database object exists

To check if a database object exists, use OBJECT_ID function. If the object is found, its system ID is returned, otherwise NULL is returned.

IF OBJECT_ID('tblMyTable') IS NOT NULL
    PRINT 'Table found'
ELSE
    PRINT 'Table not found'
Advertisements

Oracle SQL Developer – Create auto incrementing primary key

To make primary key auto increment in Oracle, you need to set the identity column property for that primary key.

Right click on the table and select Edit.

In Edit Table window, select columns, and then select your primary key column.

Go to Identity Column tab and select Column Sequence as Type. This will create a trigger and a sequence, and associate the sequence to primary key.

OracleAutoIncrement

Oracle SQL Developer – Display Date and Time

By default Oracle SQL Developer displays only a date component on date time field. You can change this behaviour in preferences.

Go to Tools -> Preferences -> Database -> NLS and change Date Format value to DD-MON-RR HH24:MI:SS (for 24 hour time display) or DD-MON-RR HH:MI:SS (for 12 hour time display).

SQLDev

Oracle – Check if field has been updated inside an update trigger

If you have an update trigger in Oracle and want to check if value of specific field has changed, use (note the single quotes around field name)

IF UPDATING('MyField') THEN

If you try to use

IF UPDATING(:NEW.MyField) THEN

it will not work, as :NEW.MyField value hasn’t actually changed, so the check will always return false.

You can also compare old and new values

IF :NEW.MyField != :OLD.MyField THEN

Mac OS X – How to enable text selection in Quick Look

Quick Look feature in OS X allows you to look at the file contents without opening the file up. Select file, press space and a Quick Look window will pop up.

This handy feature is made even better when text selection is enabled, so you can select and copy text from the file you are previewing.

To enable text selection, open terminal and type the following command:

defaults write com.apple.finder QLEnableTextSelection -bool TRUE; killall Finder

Internet Explorer – New tab shows black background

Recently Internet Explorer 10 on my Windows 7 PC started showing new tabs with black background. Today, after installing Internet Explorer 11 the black background was still there, so I decided to investigate.

It seems that this problem can occur if you change your Windows theme settings (which I did recently). To resolve the issue and have new tab in IE appear with normal background color, you need to change to a different Windows theme, and then change back to the one you were using.

Right click on your desktop and choose ‘Personalize’. If your current theme changes have not been saved, save them now by clicking on ‘Save theme’. Then choose and apply different theme. Once its applied, select your saved theme and reapply it. Open IE and new tab will be back to the normal background color.

IE Black