选择具有多个表的命令 [英] Select command with multiple tables

查看:98
本文介绍了选择具有多个表的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有两张桌子:代码和颜色。

他们的创建命令是:


创建表颜色(

Partnum varchar(10),

Eng_Color char(10),

Span_Color char(20),

Frch_Color char(20),

CONSTRAINT pkPartnum PRIMARY KEY(Partnum)




创建表格代码



Partnum varchar(10),

条形码varchar(11),

I2of5s varchar(13),

I2of5m varchar(13),

UPC varchar(11),

BigboxBCode varchar(11),

DrumBCode varchar(11),

TrayBCode varchar(11),

QtyBCode varchar(11),

CONSTRAINT fkPartnum FOREIGN KEY(Partnum)引用颜色(Partnum)



现在我的问题是,

我怎样才能给出一个select语句,这样我就可以得到所有字段

输出。

另外请注意以上是一个示例。我还有另外9张桌子,我需要一个解决方案

这样,在被Partnum引用时,我可以获得所有属性。


谢谢

Hi,
I have two tables: Code and Color.
The create command for them is :

create table Color(
Partnum varchar(10),
Eng_Color char(10),
Span_Color char(20),
Frch_Color char(20),
CONSTRAINT pkPartnum PRIMARY KEY(Partnum)
)

create table Code
(
Partnum varchar(10),
Barcode varchar(11),
I2of5s varchar(13),
I2of5m varchar(13),
UPC varchar(11),
BigboxBCode varchar(11),
DrumBCode varchar(11),
TrayBCode varchar(11),
QtyBCode varchar(11),
CONSTRAINT fkPartnum FOREIGN KEY(Partnum) references Color(Partnum)
)
Now my question is,
how can i give a select statement such that I can get all the fields as
output.
Also plz note that the above is a sample. I have another 9 tables and I
need a solution
such that on being refered by Partnum, I can get all the attributes.

Thanks

推荐答案

Shwetabh写道:
Shwetabh wrote:

我有两张桌子:代码和颜色。
它们的create命令是:

创建表颜色(
Partnum varchar(10),
Eng_Color char(10),
Span_Color char(20),
Frch_Color char(20),
CONSTRAINT pkPartnum PRIMARY KEY(Partnum)

创建表格代码

Partnum varchar(10),
条形码varchar(11),
I2of5s varchar(13),
I2of5m varchar(13),
UPC varchar(11),
BigboxBCode varchar(11),
DrumBCode varchar(11),
TrayBCode varchar(11),
QtyBCode varchar(11),
CONSTRAINT fkPartnum FOREIGN KEY(Partnum) )参考颜色(Partnum)


现在我的qu estion是,我怎么能给出一个select语句,这样我就可以得到所有字段作为
输出。
另外请注意以上是一个示例。我有另外9张桌子,我需要一个解决方案
这样,在被Partnum引用时,我可以获得所有属性。

谢谢
Hi,
I have two tables: Code and Color.
The create command for them is :

create table Color(
Partnum varchar(10),
Eng_Color char(10),
Span_Color char(20),
Frch_Color char(20),
CONSTRAINT pkPartnum PRIMARY KEY(Partnum)
)

create table Code
(
Partnum varchar(10),
Barcode varchar(11),
I2of5s varchar(13),
I2of5m varchar(13),
UPC varchar(11),
BigboxBCode varchar(11),
DrumBCode varchar(11),
TrayBCode varchar(11),
QtyBCode varchar(11),
CONSTRAINT fkPartnum FOREIGN KEY(Partnum) references Color(Partnum)
)
Now my question is,
how can i give a select statement such that I can get all the fields as
output.
Also plz note that the above is a sample. I have another 9 tables and I
need a solution
such that on being refered by Partnum, I can get all the attributes.

Thanks




我想你会想要一个内部联接。您可以在

联机丛书中阅读有关联接类型的信息。例如:


SELECT

D.partnum,D.barcode,D.i2of5s,D.i2of5m,D.upc,D.bigboxbcode,

D.drumbcode,D.traybcode,D.qtybcode,

C.eng_color,C.span_color,C.frch_color

FROM Color AS C

加入代码AS D

ON C.partnum = D.partnum;


-

大卫Portas,SQL Server MVP


只要有可能,请发布足够的代码来重现您的问题。

包含CREATE TABLE和INSERT语句通常会有所帮助。

说明您正在使用的SQL Server版本,并指定任何错误消息的内容




SQL Server联机丛书:
http://msdn2.microsoft。 com / library / m ... S,SQL.90).aspx

-



I guess you''ll want an inner join. You can read about types of joins in
Books Online. For example:

SELECT
D.partnum, D.barcode, D.i2of5s, D.i2of5m, D.upc, D.bigboxbcode,
D.drumbcode, D.traybcode, D.qtybcode,
C.eng_color, C.span_color, C.frch_color
FROM Color AS C
JOIN Code AS D
ON C.partnum = D.partnum ;

--
David Portas, SQL Server MVP

Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.

SQL Server Books Online:
http://msdn2.microsoft.com/library/m...S,SQL.90).aspx
--


Dpending您正在使用存储过程选择表格

在此范围内,哟你可以通过resutset选择每一个

结果集作为表。根据你的编码语言,那里应该有大量的例子,但是你没有发布关于你的编码环境的信息




HTH,Jens Suessmeyer。

Dpending that you are using a stored procedure Selecting the tables
within this, you can do through the resutset selecting every single
resultset as a table. Depending on your coding language there should be
masses of examples out there, butyou didn′t posted that information
about your coding enviroment.

HTH, Jens Suessmeyer.




我使用Visual Basic 6作为前端和MS SQL SERVER 2000反击

反手。

实际上我正在使用转换器将DBF中的遗留数据库转换为SQL数据库。

我希望此信息有用

Hi,
I am using Visual Basic 6 as frontend and MS SQL SERVER 2000 as
backhand.
Actually I am workin gon a converter which will convert legacy database
in DBF to SQL database.
I hope this info helps


这篇关于选择具有多个表的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆