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

问题描述



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

他们的创建命令是:


创建表颜色(

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

推荐答案




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

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


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联机丛书:


-



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
--




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

09-26 11:39