1、建立一个表,并导入数据:
Create table a (ID int, Data varchar(10))
Go
Insert into a(ID, Data)
select 1, 'ds'
union all select 2, 'dsf'
union all select 3, 'sdf'
union all select 4, 'ads'
union all select 5, 'sda'
Go
2、建立一个存储过程,返回一个结果集
Create Procedure sp_test
AS
Begin
select ID, Data from a
order by ID desc
End
3、将存储过程的结果导入到一个临时表
create table #tmp (ID int, Data varchar(10))
insert into #tmp(ID, Data)exec sp_test
select * from #tmp
drop table #tmp
4、显示结果
(所影响的行数为 5 行)
ID Data
----------- ----------
5 sda
4 ads
3 sdf
2 dsf
1 ds
(所影响的行数为 5 行)
博客介绍了使用Go语言进行数据库操作。首先建立表并导入数据,接着创建存储过程返回结果集,然后将存储过程结果导入临时表,最后显示操作结果,展示了数据库表创建、数据插入、存储过程使用等操作。

被折叠的 条评论
为什么被折叠?



