| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1008 人关注过本帖
标题:[求助]查询语句
只看楼主 加入收藏
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
 问题点数:0 回复次数:9 
[求助]查询语句
求查找语句:

查询出,一个库中所有表的列,并把此列对应的表列出

如:
user表中有id,mark
info表中有id,name,sex

查询结果:
column table
id user
mark user
id info
name info
sex info

求助!!!
搜索更多相关主题的帖子: 语句 info name user 
2007-10-24 18:22
hnj
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-10-12
收藏
得分:0 
用user表和info表连接可行吗?
2007-10-24 23:23
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 
不知道SQL2000支持sys.columns吗

我用SQL2005可以用

有高手,利用这个实现上面的效果吗?
2007-10-25 01:04
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
use databaseName
select [name] from syscolumns where id in (object_id('user'),object_id('info'))

飘过~~
2007-10-25 10:56
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 
[CODE]use Northwind
select colname=a.name,tablename=b.name from syscolumns a,sysobjects b where a.id=b.id and b.type='U'[/CODE]

SQL Server2000测试通过.

我的msn: myfend@
2007-10-25 11:06
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 
还是不行好象,一个库中理论上是有N张表的,而不止两个

实现的效果不一样???
2007-10-25 11:49
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 
其实我想要的是,把一个库中的所有列抽去出来,和列所在的表一一对应,方便核对数据.

但是我实现了半天无法实现!
请求帮忙!!!谢谢
2007-10-25 11:54
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

五楼代码效果如下.
[CODE]CustomerID Orders
EmployeeID Orders
Freight Orders
OrderDate Orders
OrderID Orders
RequiredDate Orders
ShipAddress Orders
ShipCity Orders
ShipCountry Orders
ShipName Orders
ShippedDate Orders
ShipPostalCode Orders
ShipRegion Orders
ShipVia Orders
CategoryID Products
Discontinued Products
ProductID Products
ProductName Products
QuantityPerUnit Products
ReorderLevel Products
SupplierID Products
UnitPrice Products
UnitsInStock Products
UnitsOnOrder Products
Discount Order Details
OrderID Order Details
ProductID Order Details
Quantity Order Details
UnitPrice Order Details
CustomerID CustomerCustomerDemo
CustomerTypeID CustomerCustomerDemo
CustomerDesc CustomerDemographics
CustomerTypeID CustomerDemographics
RegionDescription Region
RegionID Region
RegionID Territories
TerritoryDescription Territories
TerritoryID Territories
EmployeeID EmployeeTerritories
TerritoryID EmployeeTerritories
CategoryID t1
Discontinued t1
ProductID t1
ProductName t1
QuantityPerUnit t1
ReorderLevel t1
SupplierID t1
UnitPrice t1
UnitsInStock t1
UnitsOnOrder t1
CategoryID t2
Discontinued t2
ProductID t2
ProductName t2
QuantityPerUnit t2
ReorderLevel t2
SupplierID t2
UnitPrice t2
UnitsInStock t2
UnitsOnOrder t2
employeeid employee_Results
firstname employee_Results
lastname employee_Results
employeeid Employees_Result
firstname Employees_Result
lastname Employees_Result
Address Employees
BirthDate Employees
City Employees
Country Employees
EmployeeID Employees
Extension Employees
FirstName Employees
HireDate Employees
HomePhone Employees
LastName Employees
Notes Employees
Photo Employees
PhotoPath Employees
PostalCode Employees
Region Employees
ReportsTo Employees
Title Employees
TitleOfCourtesy Employees
CategoryID Categories
CategoryName Categories
Description Categories
Picture Categories
Address Customers
City Customers
CompanyName Customers
ContactName Customers
ContactTitle Customers
Country Customers
CustomerID Customers
Fax Customers
Phone Customers
PostalCode Customers
Region Customers
CompanyName Shippers
Phone Shippers
ShipperID Shippers
Address Suppliers
City Suppliers
CompanyName Suppliers
ContactName Suppliers
ContactTitle Suppliers
Country Suppliers
Fax Suppliers
HomePage Suppliers
Phone Suppliers
PostalCode Suppliers
Region Suppliers
SupplierID Suppliers[/CODE]

是你一楼所说的效果..


我的msn: myfend@
2007-10-25 13:01
sky_yang_sky
Rank: 3Rank: 3
等 级:论坛游民
威 望:8
帖 子:481
专家分:16
注 册:2007-5-30
收藏
得分:0 
select a.name as fields,b.name as tables from syscolumns a left join sysobjects b on a.id=b.id
這個是查詢所有表及字段,
如果是要查用戶創建的表就要用下面的
select a.name as fields,b.name as tables from syscolumns a left join sysobjects b on a.id=b.id where b.xtype='u'

你微笑的面對整個世界,整個世界也將會微笑的面對你。
2007-10-25 13:51
lhj2005
Rank: 1
等 级:新手上路
帖 子:230
专家分:0
注 册:2007-1-23
收藏
得分:0 
谢谢帮助,问题已经解决了,楼上的语法都是2000吧!谢谢各位
2007-10-25 16:58
快速回复:[求助]查询语句
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047366 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved