如何使用存储过程在表中添加列? [英] How to add a column in a table using stored procedure ?

查看:98
本文介绍了如何使用存储过程在表中添加列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i希望使用存储过程在表格中添加列但是当我尝试收到错误时



Msg 214,Level 16,State 2,过程sp_executesql,第1行

过程需要参数@statement;类型; ntext / nchar / nvarchar;



我尝试过:



  alter   proc  SpgetEMP 
as
begin
exec sp_executeSQL ' alter table emp add adrs varchar(20)null'
结束

解决方案

修改Proc如下

 声明  @ statement   as  < span class =code-keyword> nvarchar ( 100 ); 
set @ statement = ' alter table emp添加adrs varchar(20)null'
exec sp_executeSQL @ statement


hi i want to add column in a table using Stored procedure but when i am trying getting error

Msg 214, Level 16, State 2, Procedure sp_executesql, Line 1
Procedure expects parameter @statement; of type ;ntext/nchar/nvarchar;

What I have tried:

alter proc SpgetEMP
as
begin
exec sp_executeSQL  'alter table emp add adrs varchar(20) null'
end

解决方案

Modify Proc as below

declare @statement as nvarchar(100);
set @statement='alter table emp add adrs varchar(20) null'
exec sp_executeSQL @statement


这篇关于如何使用存储过程在表中添加列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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