我想从一个表中选择所有字段,但是FROM后面有三个表 [英] I want to select all fields from a table but there are three tables after FROM

查看:79
本文介绍了我想从一个表中选择所有字段,但是FROM后面有三个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下存储过程中,我只想选择Med表的所有字段,并且不想分隔其字段名,所以我想像这样使用存储过程而不选择非必需表的字段.有办法吗?

谢谢.

In the following Stored Procedure I want to select just all fields of the Med table and I want not to separate its field names, I want to use the Stored Procedure like this without selecting the fields of non required tables. Is there a way to do that?

Thanks.

USE [pharm lastver]
GO
/****** Object:  StoredProcedure [dbo].[SP_Med_SelectAllMed_ByActiveID]    Script Date: 05/14/2011 22:22:59 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
craete proc [dbo].[SP_Med_SelectAllMed_ByActiveID]
@P_Activemat_ID int
as
begin
select * from Med,Active_material,Active_mat_med
where Med.Med_ID=Active_mat_med.Med_ID
and Active_material.Activemat_ID=Active_mat_med.Activemat_ID
and Active_material.Activemat_ID=@P_Activemat_ID
end

推荐答案

您需要明确选择列.假设您在表Med中具有字段ID,名称和活动字段,则查询开始为:
You need to explicitly select the columns. Say you had the fields id, name and active in the table Med, the start of your query becomes:
select id, name, active from

通常,这是一个好习惯,因为您选择要检索的字段而没有检索想要的字段.通常,您不希望返回一两个字段,而选择它们会浪费资源.

It is generally good practice to do this as you pick the fields that you want to retrieve and don''t retrieve the ones you want. There''s normally one or two fields you don''t want returning, and selecting them is wasteful of resources.


您好,

如果要选择med表中的所有列,只需将 * 替换为 Med.* ,或者可以使用Med.column1,Med.column2,Med.column3,等...

hello,

If you want to select all the column in the med table, just replace * with Med.* or you can use Med.column1, Med.column2, Med.column3, etc...

select med.* from Med,Active_material,Active_mat_med
where Med.Med_ID=Active_mat_med.Med_ID
and Active_material.Activemat_ID=Active_mat_med.Activemat_ID
and Active_material.Activemat_ID=@P_Activemat_ID


这篇关于我想从一个表中选择所有字段,但是FROM后面有三个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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