Archive for the ‘MySQL’ Category

alter table to add new column in mysql table

Friday, October 10th, 2008

ALTER TABLE customers ADD email VARCHAR(90); This above query will add the email column with varchar type at the end of an existing table. To add the new column after a specific column, for ex: lastname, use following query: ALTER TABLE customers ADD email VARCHAR(90) AFTER lastname; If you want to add the ...

Import CSV file into mysql table using load data

Saturday, August 16th, 2008

Creating 1 row or upto 10 rows are easy manually. But what if we have to create more than 100 rows from a file? Following is the step by step procedure to import whole CSV file into the the required mysql table. 1. Create a DB called testDb. Use the existing ...

Display total rows count with LIMIT clause in MySQL

Sunday, June 8th, 2008

Assume there are lots of records in result set and want to display only few records. This concept is known as the pagination. The sql query to achieve above is, as follows, select * from books where bookcost > 3oo order by bookcost limit 0, 25; The above query will check the condition ...

Repair the corrupted table in MySQL

Sunday, April 6th, 2008

Sometimes, high load on the server, multiple INSERTs and UPDATEs, many SELECT query execution, or hardware failure, your database server may corrupt a table. The corrupted table can be repaired back using the following statement: REPAIR TABLE tablename;

Create or copy an existing MySQL table to a new table

Sunday, April 6th, 2008

You can create a new table that looks like another table. That is newly created table will have same structure and definition as of an existing table. The definitions that are copied are: Column names, Data type, precision, length, and scale, Column text. CREATE TABLE Employee1 LIKE Employee; Above statement creates the ...

Pagination using LIMIT clause in MySQL

Sunday, April 6th, 2008

MySQL supports a really cool feature for pagination is LIMIT clause. The LIMIT clause is used to limit the number of results or rows returned in a SQL statement. So if you have 500 rows in a table, and only want to return the first 20, you would do something like ...

How to Add or Drop a column from an existing MySQL table?

Saturday, January 12th, 2008

Add a column to MySQL table To add a new column col_name to the existing table table_name of VARCHAR datatype or any datatype then use ALTER TABLE as follows use the following SQL statement: ALTER TABLE table_name ADD col_name VARCHAR(size); This statement by default adds a new column at the end of ...