mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 23:28:02 +00:00
Add Show Create Statement For A Table as a mysql til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_571 TILs and counting..._
|
_572 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -251,6 +251,7 @@ _571 TILs and counting..._
|
|||||||
- [Display Output In A Vertical Format](mysql/display-output-in-a-vertical-format.md)
|
- [Display Output In A Vertical Format](mysql/display-output-in-a-vertical-format.md)
|
||||||
- [Dump A Database To A File](mysql/dump-a-database-to-a-file.md)
|
- [Dump A Database To A File](mysql/dump-a-database-to-a-file.md)
|
||||||
- [List Databases And Tables](mysql/list-databases-and-tables.md)
|
- [List Databases And Tables](mysql/list-databases-and-tables.md)
|
||||||
|
- [Show Create Statement For A Table](mysql/show-create-statement-for-a-table.md)
|
||||||
- [Show Tables That Match A Pattern](mysql/show-tables-that-match-a-pattern.md)
|
- [Show Tables That Match A Pattern](mysql/show-tables-that-match-a-pattern.md)
|
||||||
- [Show Indexes For A Table](mysql/show-indexes-for-a-table.md)
|
- [Show Indexes For A Table](mysql/show-indexes-for-a-table.md)
|
||||||
|
|
||||||
|
|||||||
30
mysql/show-create-statement-for-a-table.md
Normal file
30
mysql/show-create-statement-for-a-table.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Show Create Statement For A Table
|
||||||
|
|
||||||
|
In MySQL, you can get a quick rundown of a table using `describe users`. An
|
||||||
|
alternative to this approach is to have MySQL show the `create` statement
|
||||||
|
for a table.
|
||||||
|
|
||||||
|
```sql
|
||||||
|
> show create table users\G
|
||||||
|
*************************** 1. row ***************************
|
||||||
|
Table: users
|
||||||
|
Create Table: CREATE TABLE `users` (
|
||||||
|
`id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
|
||||||
|
`first_name` varchar(80) NOT NULL,
|
||||||
|
`last_name` varchar(80) NOT NULL,
|
||||||
|
`email` varchar(80) NOT NULL,
|
||||||
|
`middle_initial` varchar(80) NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `unique_email` (`email`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
||||||
|
```
|
||||||
|
|
||||||
|
This includes some additional information like primary key and index
|
||||||
|
information. It is also a great way to study the SQL that it takes to create
|
||||||
|
all the facets of a table.
|
||||||
|
|
||||||
|
See the [`show create table`
|
||||||
|
docs](https://dev.mysql.com/doc/refman/5.7/en/show-create-table.html) for
|
||||||
|
more details.
|
||||||
|
|
||||||
|
h/t Jake Worth
|
||||||
Reference in New Issue
Block a user