sql如何导出表结构

sql如何导出表结构,第1张

pl/sql::new->sql

window

输入查询表,右键

view

general选项面板右下角有个

(view

sql

)按钮点一下就看到表结构语句了,希望能对你有帮助

:)

1查询数据库中的所有数据库名:

SELECT Name FROM MasterSysDatabases ORDER BY Name

2查询某个数据库中所有的表名:

SELECT Name FROM SysObjects Where XType='U' ORDER BY Name

3查询表结构信息:

SELECT (case when acolorder=1 then dname else null end) 表名,

acolorder 字段序号,aname 字段名,

(case when COLUMNPROPERTY( aid,aname,'IsIdentity')=1 then '√'else '' end) 标识,

(case when (SELECT count() FROM sysobjects

WHERE (name in (SELECT name FROM sysindexes

WHERE (id = aid) AND (indid in

(SELECT indid FROM sysindexkeys

WHERE (id = aid) AND (colid in

(SELECT colid FROM syscolumns WHERE (id = aid) AND (name = aname)))))))

AND (xtype = 'PK'))>0 then '√' else '' end) 主键,bname 类型,alength 占用字节数,

COLUMNPROPERTY(aid,aname,'PRECISION') as 长度,

isnull(COLUMNPROPERTY(aid,aname,'Scale'),0) as 小数位数,(case when aisnullable=1 then '√'else '' end) 允许空,

isnull(etext,'') 默认值,isnull(g[value], ' ') AS [说明]

FROM syscolumns a

left join systypes b on axtype=bxusertype

inner join sysobjects d on aid=did and dxtype='U' and dname<>'dtproperties'

left join syscomments e on acdefault=eid

left join sysextended_properties g on aid=gmajor_id AND acolid=gminor_id

left join sysextended_properties f on did=fclass and fminor_id=0

where bname is not null

--WHERE dname='要查询的表' --如果只查询指定表,加上此条件

order by aid,acolorder

1create table  tabname like oldtab

2create table tabname select from oldtab  where 1=2

3select into tabname from oldtab where 1=2

4show create table tabname , 然后将创建表命令拷贝出来,更改table的名字,就可以建立一个完全一样的表

假设两表结构一样

1insert into tabname select from oldtab

2select into tabname from oldtab

假设两表结构不一样

1insert into tabname(field1,fields2,) select  field1,field2, from oldtab

1create table tabname select from oldtab

1、初级:使用管理工具SSMS

右侧对象树展开即可;

2、中级:sp_HelpText '表名'

3、高级:用SQL查询系统元数据

SELECT

FROM syscolumns

WHERE

分两种方法:

1、在命令窗口通过如下语句:

desc 表名;

2、用语句:

select COLUMN_NAME,DATA_TYPE,DATA_LENGTH from user_tab_cols where table_name='TEST';

以上就是关于sql如何导出表结构全部的内容,包括:sql如何导出表结构、如何在sqlserver中获取表的所有列信息、SQL如何复制表或表结构等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9296640.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存