Friday, November 25, 2011

SQLSTATE=42903

 I was in need to pass a max value in where condition. My folly, what i did is :

Incorrect : Select * from table_name where field = MAX(field);




Got below mentioned error in DB2

  42903(-120)[IBM][CLI Driver][DB2/SUN64] SQL0120N  Invalid use of an aggregate function or OLAP function.  SQLSTATE=42903
 (0.47 secs)

Correct :

Correct way is Inline Query

Select * from table_name where files = (Select MAX(filed) from table_name);

SQLSTATE=42601

 I was in need to fetch top n rows from a particular table in DB2. I got below mentioned error when tried with some incorrect syntax.

 42601(-104)[IBM][CLI Driver][DB2/SUN64] SQL0104N  An unexpected token "1" was found following "Select TOP ".  Expected tokens may include:  "".  SQLSTATE=42601
 (0.45 secs)

Correct Syntax :

Select * from table_name where filed = 'Some condition' order by field FETCH FIRST 10 ROWS ONLY;

SQLSTATE=42807

I got below mentioned error while updating a View in DB2.

 42807(-150)[IBM][CLI Driver][DB2/SUN64] SQL0150N  The target fullselect, view, typed table, materialized query table, or staging table in the INSERT, DELETE, UPDATE, or MERGE statement is a target for which the requested operation is not permitted.  SQLSTATE=42807

As the error suggest administrator have not given update permission to the user. Ask administrator to give access, else it would not be possible.

Tuesday, November 15, 2011

Step by step guide to install MySQL



Step 1. Download MySQL Installer (mysql-advanced-5.5.8-win32.msi) file from the website of MySQL 




Go to URL http://www.mysql.com/downloads/mysql/

MySQL Installer provides an easy to use, wizard-based installation experience for all your MySQL software needs. Included in the product are the latest versions of:

MySQL Server
All of our support connectors
Workbench and sample models
Sample databases
Documentation


Step 2. After downloading  the installer file e.g mysql-advanced-5.5.8-win32.msi

Open the file. It will start installer wizard. Please go throw the screen shot below.

Mostly you do not have to change the default setting, just continue with the wizard.








At this point, Note the port number. Default port number is 3306, If you wish you could change it else let go by default port number.




At this point, put password for security and note that password for login latter.


You are almost done...


Step 3. Now that MySQL is installed, You can confirm it by login to it.

Try through  Start - All programms - My SQL.

If you cannot start the server through  Start - All programms - My SQL

The best way to login without any problem is.
Go to command prompt. The folder where MySQL is installed.
Probably Program Files\MySQL\MySQL Server 5.5\bin
Use Command : mysql -u root -p
Put the password and you are in the database.



DB2 : Get all column name of a particular Table

Query :


SELECT TABNAME,COLNAME from SYSCAT.COLUMNS where TABNAME='table_name'


You can use above mentioned query for getting all column name of a particular table in DB2.