Friday, August 15, 2008

Dev : MsSQL Drop Only If Exist

If you were to execute "DROP TABLE table1" or "ALTER TABLE table1 DROP COLUMN field1" in MsSQL server, probably you'll encouter error complaining the table or the column does not exist.

So how do you verify such table or column existed before you could drop them? There is a way. By querying the "INFORMATION_SCHEMA" table, you should be able to drop it without the concern of getting error.

Instead of "DROP TABLE table1", we can use
"if exists (SELECT *
WHERE table_name = 'table1')
DROP TABLE table1".

And instead of "ALTER TABLE table1 DROP COLUMN field1", we can use
"if exists (SELECT *
WHERE table_name = 'table1'
and column_name = 'field1')
alter table table1
drop column field1".

Wednesday, August 06, 2008

Dev : div vs span tag

Some of us may come across with the <div>and <span> tag before. What is the difference? Both usage seems almost the same.

Well, not exactly the same, but yes, almost. Both are elements of a document, but <div>is a block element and <span> is an inline element. And what is block and inline? Block elements take the whole section of a page, at least a whole full line, but inline will use as little space as possible, just like filling a gap.

I am <div>a</div>boy.
will produce
I am

I am <span>a</span> boy
will produce
I am a boy.

So, can you see the differences now?