Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 485 Vote(s) - 3.48 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I show the schema of a table in a MySQL database?

#1
From the [MySQL](

[To see links please register here]

) console, what command displays the schema of any given table?
Reply

#2
SHOW CREATE TABLE yourTable;
or

SHOW COLUMNS FROM yourTable;
Reply

#3
You can also use shorthand for describe as `desc` for table description.

> desc [db_name.]table_name;

or

> use db_name; <br>
> desc table_name;

You can also use `explain` for table description.

> explain [db_name.]table_name;

See [official doc](

[To see links please register here]

)

Will give output like:

+----------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| id | int(10) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(10) | YES | | NULL | |
| sex | varchar(10) | YES | | NULL | |
| sal | int(10) | YES | | NULL | |
| location | varchar(20) | YES | | Pune | |
+----------+-------------+------+-----+---------+-------+


Reply

#4
SELECT COLUMN_NAME, TABLE_NAME,table_schema
FROM INFORMATION_SCHEMA.COLUMNS;
Reply

#5
Perhaps the question needs to be slightly more precise here about what is required because it *can* be read it two different ways. i.e.

1. How do I get the structure/definition for a table in mysql?
2. How do I get the name of the schema/database this table resides in?

Given the accepted answer, the OP clearly intended it to be interpreted the first way. For anybody reading the question the other way try

SELECT `table_schema`
FROM `information_schema`.`tables`
WHERE `table_name` = 'whatever';

Reply

#6
For formatted output:

describe [db_name.]table_name;

For an SQL statement that can be used to create a table:

show create table [db_name.]table_name;

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through