1,创建数据表
use test create table money( id int identity(1,1) primary key, money int, monetary_unity char );
2,考虑到货币单位的缩写一般是3个字符,所以更改货币单位的长度
alter table [testdb].[dbo].[money] alter column monetary_unity char(3)
3,往新的表中插入几行数据
use testdb insert into [testdb ].[dbo].[money] values (1,'usd') insert into [testdb ].[dbo].[money] values(11,'rmb') insert into [testdb ].[dbo].[money] values(7,'hkd') insert into [testdb ].[dbo].[money] values(32,'eur')
4,创建一个查询的存储过程并执行,绿色部分为注释
--search if a procedure named usp_getAllMoneyInfo has existed,then drop it if exists (select * from sysobjects where name='usp_getAllMoneyInfo') drop proc usp_getAllMoneyInfo go --definition a procedure create proc usp_getAllMoneyInfo ---some parameters must be definited before as as ---mask to do select * from money go ---execute the procedure exec usp_getAllMoneyInfo
5,修改一个存储过程,注意,修改存储过程时,一定是要在当前库的试图下(即management studio左上角的available databases 值是当前数据表所在的库),否则会报该存储过程无法解析!
并且,修改存储过程时,当前窗口只能有一个可用的存储过程,否则会报错如下图所示:
alter procedure usp_getAllMoneyInfo as insert into [testdb].[dbo].[money] values(44,'gbp') go exec usp_getAllMoneyInfo
6,创建一个修改某字段的存储过程
alter procedure usp_getAllMoneyInfo as update money set monetary_unity ='cny' where money=11 go exec usp_getAllMoneyInfo
学习创建存储过程并顺便复习了一下sql基本语法吧。
其中关于GO的含义详见 https://blog.csdn.net/zhangqidashu/article/details/17250321
本文转载自 https://www.cnblogs.com/c-supreme/p/9482321.html 感谢作者分享