本文介绍了创建存储过程以将新数据插入表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个存储过程来在表 'dbo.Terms' 中插入一个新行
I want to create a stored procedure to insert a new row in a table 'dbo.Terms'
CREATE PROCEDURE dbo.terms
@Term_en NVARCHAR(50) = NULL ,
@Createdate DATETIME = NULL ,
@Writer NVARCHAR(50) = NULL ,
@Term_Subdomain NVARCHAR(50) = NULL
AS
BEGIN
SET NOCOUNT ON
INSERT INTO dbo.terms
(
Term_en ,
Createdate ,
Writer ,
Term_Subdomain
)
VALUES
(
@Term_en = 'Cat' ,
@Createdate = '2013-12-12' ,
@Writer = 'Fadi' ,
@Term_Subdomain = 'English'
)
END
GO
但是这里显示了一个错误 (@Term_en = 'Cat') 不正确的语法有什么帮助吗?
But is shows me an error here ( @Term_en = 'Cat') incorrect syntaxAny help?
推荐答案
我假设您想将值 cat 等插入表中;为此,您需要使用过程变量中的值.我不会将您的程序与您的表同名,它会引起各种混乱;您可以找到一些关于命名标准的好资源(或来自 Adventureworks)
I presume you want to insert the values cat etc into the table; to do that you need to use the values from your procedures variables. I wouldn't call your procedure the same name as your table it will get all kinds of confusing; you can find some good resources for naming standards (or crib from Adventureworks)
CREATE PROCEDURE dbo.terms
@Term_en NVARCHAR(50) = NULL ,
@Createdate DATETIME = NULL ,
@Writer NVARCHAR(50) = NULL ,
@Term_Subdomain NVARCHAR(50) = NULL
AS
BEGIN
SET NOCOUNT ON
INSERT INTO dbo.terms
(
Term_en ,
Createdate ,
Writer ,
Term_Subdomain
)
VALUES
(
@Term_en,
@Createdate,
@Writer,
@Term_Subdomain
)
END
GO
并进行测试
exec dbo.terms
@Term_en = 'Cat' ,
@Createdate = '2013-12-12' ,
@Writer = 'Fadi' ,
@Term_Subdomain = 'English'
这篇关于创建存储过程以将新数据插入表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!