Sunday, October 12, 2008

MySQL Row Number

Use the following MySQL query to return a row number for each record in a recordset:

SELECT @row := @row + 1 AS `RowNumber`, SomeTable.*
FROM SomeTable, (SELECT @row := 0) `DerivedTable`;

Explanation

MySQL allows variables to be assigned and selected in the same statement; therefore, @row := @row + 1 increments the value of the @row variable by one and selects the result. Because the default configuration of MySQL does not allow multiple queries, the value of @row is initialized through a sub-select in the FROM portion of the query. It is important to note that MySQL requires a name for each derived table, in this case the derived table was named DerivedTable. SomeTable and SomeTable.* should be replaced with your table and field list respectively.

Alternate Syntax

If MySQL is configured to allow multiple statements per command (this is turned off by default to prevent several types of SQL injection attacks), you can use the following alternate syntax, which does not require a derived table:

SET @i = 0;
SELECT @i := @i + 1 AS RowNumber, SomeTable.*
FROM SomeTable;

MySQL Numeric Data Types

Signed

Type Minimum Maximum
TINYINT
(1 Byte)
-128 127
SMALLINT
(2 Bytes)
-32768 32767
MEDIUMINT
(3 Bytes)
-8388608 8388607
INT
(4 Bytes)
-2147483648 2147483647
BIGINT
(8 Bytes)
-9223372036854775808 9223372036854775807

Unsigned

Type Minimum Maximum
TINYINT
(1 Byte)
0 255
SMALLINT
(2 Bytes)
0 65535
MEDIUMINT
(3 Bytes)
0 16777215
INT
(4 Bytes)
0 4294967295
BIGINT
(8 Bytes)
0 18446744073709551615

Source MySQL Numeric Data Types

Saturday, October 04, 2008

Microsoft to Ship jQuery with Visual Studio

Microsoft has announced they will be shipping the JavaScript jQuery library with Visual Studio. From the jQuery Blog:

We have two pieces of fantastic, albeit serendipitous, news today: Both Microsoft and Nokia are taking the major step of adopting jQuery as part of their official application development platform. Not only will they be using it for their corporate development but they will be providing it as a core piece of their platform for developers to build with.

This is important news for developers because they will now be able to standardize on the jQuery library for all JavaScript development.