Sunday, October 9, 2011

[MySQL] Data Type: int(5)


Numeric Type Attributes

MySQL supports an extension for optionally specifying the display width of integer data types in parentheses following the base keyword for the type. For example, INT(4) specifies an INT with a display width of four digits. This optional display width may be used by applications to display integer values having a width less than the width specified for the column by left-padding them with spaces. (That is, this width is present in the metadata returned with result sets. Whether it is used or not is up to the application.)

The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly. For example, a column specified asSMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using more than three digits.

When used in conjunction with the optional (nonstandard) attribute ZEROFILL, the default padding of spaces is replaced with zeros. For example, for a column declared as INT(4) ZEROFILL, a value of 5 is retrieved as 0005.

Note

The ZEROFILL attribute is ignored when a column is involved in expressions or UNION queries.

If you store values larger than the display width in an integer column that has the ZEROFILL attribute, you may experience problems when MySQL generates temporary tables for some complicated joins. In these cases, MySQL assumes that the data values fit within the column display width.

All integer types can have an optional (nonstandard) attribute UNSIGNED. Unsigned type can be used to permit only nonnegative numbers in a column or when you need a larger upper numeric range for the column. For example, if an INT column is UNSIGNED, the size of the column's range is the same but its endpoints shift from -2147483648 and 2147483647 up to 0 and 4294967295.

Floating-point and fixed-point types also can be UNSIGNED. As with integer types, this attribute prevents negative values from being stored in the column. Unlike the integer types, the upper range of column values remains the same.

If you specify ZEROFILL for a numeric column, MySQL automatically adds the UNSIGNED attribute to the column.

Integer or floating-point data types can have the additional attribute AUTO_INCREMENT. When you insert a value ofNULL (recommended) or 0 into an indexed AUTO_INCREMENT column, the column is set to the next sequence value. Typically this is value+1, where value is the largest value for the column currently in the table.AUTO_INCREMENT sequences begin with 1.

Saturday, October 8, 2011

[SQL] JOIN


http://www.firebirdfaq.org/faq93/


What's the difference between LEFT, RIGHT, INNER, OUTER, JOIN?


The difference is in the way tables are joined if there are no common records.

JOIN is same as INNER JOIN and means to only show records common to both tables. Whether the records are common is determined by the fields in join clause. For example:

FROM t1
JOIN t2 on t1.ID = t2.ID

means show only records where the same ID value exists in both tables.

LEFT JOIN is same as LEFT OUTER JOIN and means to show all records from left table (i.e. the one that precedes in SQL statement) regardless of the existance of matching records in the right table.

RIGHT JOIN is same as RIGHT OUTER JOIN and means opposite of LEFT JOIN, i.e. shows all records from the second (right) table and only matching records from first (left) table.

-------------------------------------------------------------------------------



These 3 mysql queries have the same results


mysql> SELECT name FROM animal WHERE id NOT IN (SELECT animal_id FROM animal_food);


mysql> SELECT name FROM animal LEFT JOIN animal_food ON animal.id=animal_id WHERE animal_id IS NULL;



mysql> SELECT name FROM animal WHERE NOT EXISTS (SELECT animal_id FROM animal_food WHERE animal.id=animal_id);



Friday, October 7, 2011

Eclipse Switching Tabs

Alternating File Tabs by pressing Ctrl + TAB

Even with many files open in the eclipse editor, only two files can be navigated alternatingly by Ctrl + TAB

To configure

    Windows -> Preferences -> General -> Keys

1. Unbind "Next Tab"
    Eclipse says that "Next Tab" is Switch to the next tab which I have no knowledge about

    Type in Next Tab to locate Next Tab and click on Unbind Command

Unbind Next Tab


2. Bind "Next Ed"
    Find it and bind a new command with "Ctrl + Tab"

Bind Next Editor


Two things will be noticed

1. While holding the Ctrl key, if the TAB key is pressed, then the previously worked file will be focused

    Let go off the Ctrl + TAB, and doing it again will focus on the previous file again

    So only two files will be alternatingly navigated without being bothered by others which are still open

    If a file tab is mouse-clicked, then it will become the current tab as if it was selected by Ctrl + Tab

2. If the Ctrl key is still being pressed, many TAB keys will navigate the files in the order they file names are buffered


* The alternating navigation between just the two files has nothing to do with "Previous Editor"

Bind Next Editor