谢谢!!
12 个解决方案
#1
请各位赐教!!
#2
For example:
"
use northwind
go
sp_columns orders
"
取出表结构,拷贝到excel ,Word 即可。
"
use northwind
go
sp_columns orders
"
取出表结构,拷贝到excel ,Word 即可。
#3
我的表有500多个,
这样COPY太麻烦,有没有更好的办法,谢谢!!!
这样COPY太麻烦,有没有更好的办法,谢谢!!!
#4
在enterprise manager中右击你的数据库,选择export data即可
#5
不知道你是想要什么样的格式,能不能说清楚一点?
如果你想要到EXCEL中是SQL语句的话,用SQLDMO来生成SQL语句,然后写入EXCEL。
如果只要表名,列名,类型等信息,你用这样的语句:
select syscolumns.*,sysobjects.xtype
from syscolumns join sysobjects on syscolumns.id=sysobjects.id and sysobjects.xtype='U'
order by syscolumns.id,colid
生成的记录集引出就可以了。
上面是选出所有列名,你可以选择性地SELECT。
如果你想要到EXCEL中是SQL语句的话,用SQLDMO来生成SQL语句,然后写入EXCEL。
如果只要表名,列名,类型等信息,你用这样的语句:
select syscolumns.*,sysobjects.xtype
from syscolumns join sysobjects on syscolumns.id=sysobjects.id and sysobjects.xtype='U'
order by syscolumns.id,colid
生成的记录集引出就可以了。
上面是选出所有列名,你可以选择性地SELECT。
#6
按右建选择“导出”,在源地选本地数据库,目的地挑excel,
选择要的表,导出即可
选择要的表,导出即可
#7
icevi兄,怎么可以连表名也显示出来呢?
#8
我是这样做的,选择数据库下的所有表,再复制(CRRL+C)到 WORD中再粘贴就是了!
或者是用VISIO来做,可以导出所有的表(效果都好的,我写文档都用它),我硬盘上的VISIO有70多M呢,
或者是用VISIO来做,可以导出所有的表(效果都好的,我写文档都用它),我硬盘上的VISIO有70多M呢,
#9
你给我一个足够大的邮箱,我发给你好了 :)
#10
使用下面的存储过程:
如果输入表名则取出此表,如果不输入表名则选出全表结构,有问题请继续问我。
--此存储过程可以取出所输入表的字段信息,如果表名为空则列出当前数据库中的所有表的信息,
--如果@WITHVIEW参数不为0则列出视图的字段信息,为0则不列视图信息
CREATE PROCEDURE TABLE_INFO(@TABLENAME VARCHAR(50),@WITHVIEW BIT=0 )
AS
BEGIN
if NOT exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[DATADICT]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
IF @TABLENAME IS NULL
BEGIN
IF @WITHVIEW=0
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U' OR O.TYPE='V')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
SELECT C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,
C.SCALE AS 小数位数 ,
可否为空= CASE C.ISNULLABLE WHEN 0 THEN 'YES'
ELSE 'NO'END FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND O.NAME=@TABLENAME
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
IF NOT @TABLENAME IS NULL
BEGIN
SELECT @TABLENAME AS 表名, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C
WHERE ID = OBJECT_ID(@TABLENAME) AND B.XTYPE=A.XTYPE
AND C.FIELDS=*A.NAME
AND C.TABLENAME=@TABLENAME
ORDER BY A.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C,SYSOBJECTS AS O
WHERE A.ID = O.ID
AND B.XUSERTYPE=A.XUSERTYPE
AND C.FIELDS=*A.NAME
AND (O.TYPE='U' OR O.TYPE='V')
AND C.TABLENAME=*O.NAME
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE, O.NAME,A.NAME
END
END
END
GO
如果输入表名则取出此表,如果不输入表名则选出全表结构,有问题请继续问我。
--此存储过程可以取出所输入表的字段信息,如果表名为空则列出当前数据库中的所有表的信息,
--如果@WITHVIEW参数不为0则列出视图的字段信息,为0则不列视图信息
CREATE PROCEDURE TABLE_INFO(@TABLENAME VARCHAR(50),@WITHVIEW BIT=0 )
AS
BEGIN
if NOT exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[DATADICT]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
IF @TABLENAME IS NULL
BEGIN
IF @WITHVIEW=0
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U' OR O.TYPE='V')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
SELECT C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,
C.SCALE AS 小数位数 ,
可否为空= CASE C.ISNULLABLE WHEN 0 THEN 'YES'
ELSE 'NO'END FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND O.NAME=@TABLENAME
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
IF NOT @TABLENAME IS NULL
BEGIN
SELECT @TABLENAME AS 表名, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C
WHERE ID = OBJECT_ID(@TABLENAME) AND B.XTYPE=A.XTYPE
AND C.FIELDS=*A.NAME
AND C.TABLENAME=@TABLENAME
ORDER BY A.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C,SYSOBJECTS AS O
WHERE A.ID = O.ID
AND B.XUSERTYPE=A.XUSERTYPE
AND C.FIELDS=*A.NAME
AND (O.TYPE='U' OR O.TYPE='V')
AND C.TABLENAME=*O.NAME
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE, O.NAME,A.NAME
END
END
END
GO
#11
刚才忘记了,取出结构后还得拷贝进word或excel.
#12
使用Sql Server的导入/导出数据工具导出选择源数据为Sql Server上要导出的DbName,选择目标数据Microsoft Excel 97-2000及填写目标Excel文件名导出即可
#1
请各位赐教!!
#2
For example:
"
use northwind
go
sp_columns orders
"
取出表结构,拷贝到excel ,Word 即可。
"
use northwind
go
sp_columns orders
"
取出表结构,拷贝到excel ,Word 即可。
#3
我的表有500多个,
这样COPY太麻烦,有没有更好的办法,谢谢!!!
这样COPY太麻烦,有没有更好的办法,谢谢!!!
#4
在enterprise manager中右击你的数据库,选择export data即可
#5
不知道你是想要什么样的格式,能不能说清楚一点?
如果你想要到EXCEL中是SQL语句的话,用SQLDMO来生成SQL语句,然后写入EXCEL。
如果只要表名,列名,类型等信息,你用这样的语句:
select syscolumns.*,sysobjects.xtype
from syscolumns join sysobjects on syscolumns.id=sysobjects.id and sysobjects.xtype='U'
order by syscolumns.id,colid
生成的记录集引出就可以了。
上面是选出所有列名,你可以选择性地SELECT。
如果你想要到EXCEL中是SQL语句的话,用SQLDMO来生成SQL语句,然后写入EXCEL。
如果只要表名,列名,类型等信息,你用这样的语句:
select syscolumns.*,sysobjects.xtype
from syscolumns join sysobjects on syscolumns.id=sysobjects.id and sysobjects.xtype='U'
order by syscolumns.id,colid
生成的记录集引出就可以了。
上面是选出所有列名,你可以选择性地SELECT。
#6
按右建选择“导出”,在源地选本地数据库,目的地挑excel,
选择要的表,导出即可
选择要的表,导出即可
#7
icevi兄,怎么可以连表名也显示出来呢?
#8
我是这样做的,选择数据库下的所有表,再复制(CRRL+C)到 WORD中再粘贴就是了!
或者是用VISIO来做,可以导出所有的表(效果都好的,我写文档都用它),我硬盘上的VISIO有70多M呢,
或者是用VISIO来做,可以导出所有的表(效果都好的,我写文档都用它),我硬盘上的VISIO有70多M呢,
#9
你给我一个足够大的邮箱,我发给你好了 :)
#10
使用下面的存储过程:
如果输入表名则取出此表,如果不输入表名则选出全表结构,有问题请继续问我。
--此存储过程可以取出所输入表的字段信息,如果表名为空则列出当前数据库中的所有表的信息,
--如果@WITHVIEW参数不为0则列出视图的字段信息,为0则不列视图信息
CREATE PROCEDURE TABLE_INFO(@TABLENAME VARCHAR(50),@WITHVIEW BIT=0 )
AS
BEGIN
if NOT exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[DATADICT]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
IF @TABLENAME IS NULL
BEGIN
IF @WITHVIEW=0
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U' OR O.TYPE='V')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
SELECT C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,
C.SCALE AS 小数位数 ,
可否为空= CASE C.ISNULLABLE WHEN 0 THEN 'YES'
ELSE 'NO'END FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND O.NAME=@TABLENAME
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
IF NOT @TABLENAME IS NULL
BEGIN
SELECT @TABLENAME AS 表名, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C
WHERE ID = OBJECT_ID(@TABLENAME) AND B.XTYPE=A.XTYPE
AND C.FIELDS=*A.NAME
AND C.TABLENAME=@TABLENAME
ORDER BY A.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C,SYSOBJECTS AS O
WHERE A.ID = O.ID
AND B.XUSERTYPE=A.XUSERTYPE
AND C.FIELDS=*A.NAME
AND (O.TYPE='U' OR O.TYPE='V')
AND C.TABLENAME=*O.NAME
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE, O.NAME,A.NAME
END
END
END
GO
如果输入表名则取出此表,如果不输入表名则选出全表结构,有问题请继续问我。
--此存储过程可以取出所输入表的字段信息,如果表名为空则列出当前数据库中的所有表的信息,
--如果@WITHVIEW参数不为0则列出视图的字段信息,为0则不列视图信息
CREATE PROCEDURE TABLE_INFO(@TABLENAME VARCHAR(50),@WITHVIEW BIT=0 )
AS
BEGIN
if NOT exists (select * from dbo.sysobjects
where id = object_id(N'[dbo].[DATADICT]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
IF @TABLENAME IS NULL
BEGIN
IF @WITHVIEW=0
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
,C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,C.SCALE AS 小数位数 ,
可否为空=
CASE C.ISNULLABLE
WHEN 0
THEN 'YES'
ELSE 'NO'
END
FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND (O.TYPE='U' OR O.TYPE='V')
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
SELECT C.NAME AS 列名,T.NAME AS 类型,C.LENGTH AS 长度,C.PREC 精度,
C.SCALE AS 小数位数 ,
可否为空= CASE C.ISNULLABLE WHEN 0 THEN 'YES'
ELSE 'NO'END FROM SYSCOLUMNS C,SYSOBJECTS O ,SYSTYPES T
WHERE T.USERTYPE=C.USERTYPE AND
O.ID=C.ID AND O.NAME=@TABLENAME
ORDER BY O.TYPE,O.NAME,C.NAME
END
END
ELSE
BEGIN
IF NOT @TABLENAME IS NULL
BEGIN
SELECT @TABLENAME AS 表名, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C
WHERE ID = OBJECT_ID(@TABLENAME) AND B.XTYPE=A.XTYPE
AND C.FIELDS=*A.NAME
AND C.TABLENAME=@TABLENAME
ORDER BY A.NAME
END
ELSE
BEGIN
SELECT 表名= CASE O.TYPE WHEN 'V' THEN '视图:'+ O.NAME ELSE '表:'+ O.NAME END
, A.NAME AS 列名,C.EXPLAIN AS 说明, B.NAME AS 数据类型,
A.LENGTH AS 长度,A.XPREC AS 精度,A.XSCALE AS 小数位数
FROM SYSCOLUMNS A ,SYSTYPES AS B,DATADICT AS C,SYSOBJECTS AS O
WHERE A.ID = O.ID
AND B.XUSERTYPE=A.XUSERTYPE
AND C.FIELDS=*A.NAME
AND (O.TYPE='U' OR O.TYPE='V')
AND C.TABLENAME=*O.NAME
AND O.NAME NOT IN ('SYSCONSTRAINTS','SYSSEGMENTS')
ORDER BY O.TYPE, O.NAME,A.NAME
END
END
END
GO
#11
刚才忘记了,取出结构后还得拷贝进word或excel.
#12
使用Sql Server的导入/导出数据工具导出选择源数据为Sql Server上要导出的DbName,选择目标数据Microsoft Excel 97-2000及填写目标Excel文件名导出即可