Wednesday, May 9, 2007

Doctype and browser compatibility

I recommend setting a doctype in your web pages. If you specify the right doctype, then you can avoid IE dropping into "quirks mode" ("quirks mode" = IE backwords compatibility mode). Thus, your pages will look almost the same in IE and Firefox.

You can get a list of doctypes here:
http://www.w3.org/QA/2002/04/valid-dtd-list.html

If you specify an "HTML" doctype, and use DHTML, then your jsp pages may still be in quirks mode. I recommend using an XHTML doctype to solve this problem, like this doctype for example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"

Wednesday, May 2, 2007

SQL: Adding foreign key relationships

Tip on adding foreign key relationships in SQL:

You can establish a foreign key relation in your create table or with an alter table statment, like this:

ALTER TABLE [table1_name]
ADD CONSTRAINT [constraint_name]
FOREIGN KEY ([field(s) from table1])
REFERENCES [table2_name] ([field(s) from table2])
ON [DELETE CASCADE, or UPDATE, or other command];

(BTW, in the example above, for a cascade, generally table1 would be the child table, and table2 would be the parent table)

If you get an error like this:
Error Code : 1005
Can't create table '.\test\#sql-ac_195.frm' (errno: 150)

it may be the case that your referenced field is not guaranteed unique, which it must be. If you don't have a single unique field in that table, you can use multiple fields to specify the unique key.

Tuesday, May 1, 2007

Establishing primary key auto creates index

In MySQL, you can have a primary key constraint on one or more columns. Establishing a primary key causes MySQL to automatically make a unique key that consists of the columns specified in the primary key. You can verify the existence of this key by running the command:

SHOW INDEX FROM [table name];

In the resulting output, the column 'Non_unique' shows '0' if the column is unique, and '1' if the column is not unique.

SQLyog

I want to recommend the software I use for managing my MySQL databases. It is called SQLyog. You can find it online for download. It is free, although you can buy upgraded versions. It is great for running queries, manipulating data, imports, exports, and you can even manage indexes/triggers/etc.