Month: March 2012

  • Copying tables in MySQL

    There are multiple ways this can be done. I will mention two here. Method 1 In MySQL, run these statements: /*This will create table2 with the schema of table1*/ CREATE TABLE `table2` LIKE `table1` /*This will copy the data from table1 to table2*/ INSERT INTO `table2` SELECT * FROM `table1` Method 2 On the command…

  • Get just the fields names of a table in MySQL

    If you do: describe `table_name` Mysql will give you table information which will contain field names, their types, etc. What if you want just the field names and nothing else? You can run this query and do just that: SELECT column_name FROM INFORMATION_SCHEMA.columns WHERE table_name = ‘tablename’ AND table_schema = ‘dbname’;