简体   繁体   中英

how can I get the sql statements used to create a specific table?

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?

SHOW CREATE TABLE tablename (仅适用于MySQL)

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)+')'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM