我是SQL Server的新手,我想问一些关于插入和更新数据的问题。 我想为我的Select - Insert - Delete - Update创建存储过程。
我正在为我的应用程序使用ASP.NET。
首先让我给你我的数据库架构。我在SQL Server 2008中工作
我有4张桌子 -
tbl_Equipment | tbl_Location | tbl_Condition | tbl_Category
tbl_Equipment
:
tbl_Category
:
tbl_Condition
:
tbl_Location
:
表Condition
,Location
和Category
是查找表。
我想在表Equipment
中插入值,并从查找表中的下拉列表中进行选择并更新我的数据。
我尝试过的一种小方法:
我的选择
SELECT
tbl_Equipment.Product,
tbl_Equipment.AquiredDate,
tbl_Equipment.SerialNumber,
tbl_Equipment.PurchasedPlace,
tbl_Equipment.Manufacturer,
tbl_Equipment.Model,
tbl_Equipment.Comments,
tbl_Condition.Condition,
tbl_Category.Category,
tbl_Location.Location
FROM
tbl_Category
INNER JOIN
tbl_Equipment ON tbl_Category.categ_ID = tbl_Equipment.categ_ID
INNER JOIN
tbl_Condition ON tbl_Equipment.cond_ID = tbl_Condition.cond_ID
INNER JOIN
tbl_Location ON tbl_Equipment.loc_ID = tbl_Location.loc_ID>
我的插入
CREATE PROCEDURE insertEquipTable
@Product nvarchar(50),
@AquiredDate datetime,
@SerialNumber nvarchar(20),
@PurchasedPlace nvarchar(50),
@Insured nvarchar(10),
@Manufacturer nvarchar(50),
@Model nvarchar(50),
@Comments nvarchar(50),
@categ_ID int,
@cond_ID int,
@loc_ID int
AS
BEGIN
SET NOCOUNT ON;
SELECT
tbl_Equipment.Product,
tbl_Equipment.AquiredDate,
tbl_Equipment.SerialNumber,
tbl_Equipment.PurchasedPlace,
tbl_Equipment.Insured,
tbl_Equipment.Manufacturer,
tbl_Equipment.Model,
tbl_Equipment.Comments,
tbl_Category.Category,
tbl_Condition.Condition,
tbl_Location.Location,
tbl_Equipment.categ_ID,
tbl_Equipment.cond_ID,
tbl_Equipment.loc_ID
FROM
tbl_Category
INNER JOIN
tbl_Equipment ON tbl_Category.categ_ID = tbl_Equipment.categ_ID
INNER JOIN
tbl_Condition ON tbl_Equipment.cond_ID = tbl_Condition.cond_ID
INNER JOIN
tbl_Location ON tbl_Equipment.loc_ID = tbl_Location.loc_ID
INSERT INTO tbl_Equipment(Product, AquiredDate, SerialNumber, PurchasedPlace, Insured,
Manufacturer, Model, Comments, categ_ID, cond_ID, loc_ID)
VALUES(@Product, @AquiredDate, @SerialNumber, @PurchasedPlace, @Insured,
@Manufacturer, @Model, @Comments, @categ_ID, @cond_ID, @loc_ID)
END
任何帮助将不胜感激。或者如果我的问题还有另一种方法,比如枚举等。
感谢您的时间,对不起我的错误代码类型感到抱歉。