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?
Asked
Active
Viewed 103 times
2 Answers
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