1

Suppose if I have access to a mysql database, and there exists a table named "users", how could I get the sql statements used to create that specific table? Is there any way to do it by a simple command in mysql shell?

DesirePRG
  • 6,122
  • 15
  • 69
  • 114
  • possible duplicate of [How to generate a create table script for an existing table in phpmyadmin?](http://stackoverflow.com/questions/11739014/how-to-generate-a-create-table-script-for-an-existing-table-in-phpmyadmin) – Salman A Apr 02 '15 at 13:44

2 Answers2

4

SHOW CREATE TABLE tablename (mysql only)

paul
  • 21,653
  • 1
  • 53
  • 54
0

in MS SQL

It is pretty long but it is what I do when needed

declare @clms nvarchar(max)
declare @tbl nvarchar(max)='a1'


select @clms= coalesce(@clms,'(')+column_name+ ' '+data_type+

 case  when data_type in ('nvarchar','varchar','char') then '(255)' else '' end + ', '
from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME=@tbl



 select 'create table ' + @tbl +left(@clms,len(@clms)-1)+')'
koushik veldanda
  • 1,079
  • 10
  • 23