Translator

database

Oracle SQL: Create new column, renama a column, change data type of column

Oracle SQL Create new column:
alter table tablename1 add project_codes varchar2(3);

Oracle SQL Rename:
alter table tablename1 rename column project to projects;

Oracle SQL change data type:
alter table tablename1 modify projects varchar2(20);

Oracle Commands

How to Duplicate existing table in oracle

create table table_name2 as select * from table_name1

How to Drop database in Oracle XE (10 g)

How to drop database in Oracle XE (10g)

Open cmd

sqlplus / as sysdba

SQL> shutdown immediate;
oracle database closed
oracle database dismounted
oracle instance shutdown

SQL> startup restrict mount;

SQL> drop database;

Database dropped

SQL> exit

Optimizing MySQL

Today i have encounter a problem where mysql used by our clients got hang.

And after 2 days of searching, i finally know that using too many left join (joining mysql table) while NOT INDEXING it would make database queries too long that can cause database hang.

The solution this situation is by using mysql index.

To retrieve rows from other tables when performing joins. MySQL can use indexes on columns more efficiently if they are declared as the same type and size. In this context, VARCHAR and CHAR are considered the same if they are declared as the same size. For example, VARCHAR(10) and CHAR(10) are the same size, but VARCHAR(10)and CHAR(15) are not.

Comparison of dissimilar columns may prevent use of indexes if values cannot be compared directly without conversion. Suppose that a numeric column is compared to a string column. For a given value such as 1 in the numeric column, it might compare equal to any number of values in the string column such as '1'' 1','00001', or '01.e1'. This rules out use of any indexes for the string column.

from http://dev.mysql.com/doc/refman/5.1/en/mysql-indexes.html

You can read more about this and how to create indexes as below:

http://dev.mysql.com/doc/refman/5.1/en/mysql-indexes.html

http://dev.mysql.com/doc/refman/5.0/en/create-index.html

MySQL Tips

Collections of MySQL Tips\Tutorial:

http://blog.tuvinh.com/top-20-mysql-best-practices/

Comment: Very simple yet practical tips to improve your mysql query speed.