How to Check table structure in MySQL

September 28th, 2011 by Pankaj Joshi Leave a reply »

in our previous  post we discussed how to  add more columns in MySQL table , lets see how we can check table structure in MySQL.

Step 1) Login to MySQL

we will be using user : demo and password as demouser

mysql -u demo -p demouser

Step 2) use database in which we need to check table , as in our previous post we created database demo we will be using same database

mysql> use demo;

Step 3) we have 2 methods of checking the table structure.

a) Using Desc , we will now check the table structure of table employee

mysql> desc employee;
+————–+————–+——+—–+———+——-+
| Field        | Type         | Null | Key | Default | Extra |
+————–+————–+——+—–+———+——-+
| id           | int(11)      | YES  |     | NULL    |       |
| employeename | varchar(252) | YES  |     | NULL    |       |
| address      | varchar(256) | YES  |     | NULL    |       |
+————–+————–+——+—–+———+——-+
3 rows in set (0.07 sec)

This command lists all the columns and data type used for each column.

b) Using show create table command

syntax : show create table tablename

mysql> show create table employee;

+———-+———————————————————————————————————————————————————————————+

| Table    | Create Table                                                                                                                                                                    |

+———-+———————————————————————————————————————————————————————————+

| employee | CREATE TABLE `employee` (

`id` int(11) default NULL,

`employeename` varchar(252) default NULL,

`address` varchar(256) default NULL

) ENGINE=MyISAM DEFAULT CHARSET=latin1 |

+———-+———————————————————————————————————————————————————————————+

1 row in set (0.00 sec)

This command gives us create table structure for table employee.

In next post we will discuss how to check how many tables exists in a database.

Advertisement
  • http://onaxer.com/blog/blog/2011/09/28/how-to-insert-data-in-mysql-table/ How to insert data in MySQL Table | Nix World

    [...] start inserting data in the table created in our post, table name was employee, we also discussed how to check the table structure in one of our [...]

blog comments powered by Disqus