表 T1 (id(int主键),name vachar(20),age vachar(10))
要求 建一存储过程,insert into T1 (name,age)values(x, y)
x,y,可以为任意值, 要求 执行insert into T1 (name,age)values(x, y)
100遍
求存储过程。
要求 建一存储过程,insert into T1 (name,age)values(x, y)
x,y,可以为任意值, 要求 执行insert into T1 (name,age)values(x, y)
100遍
求存储过程。
AS
INSERT INTO T1(name,age)
SELECT TOP 100 @name,@age
FROM master.dbo.spt_values;
GO
AS
INSERT INTO T1(name,age)
SELECT TOP 100 @name,@age
FROM master.dbo.spt_values;
GO
go
CREATE PROC p
AS
INSERT INTO T1(name,age)
select top 100 name,RTRIM(id) from syscolumns a;
GO
exec p--调用存储过程
select * from T1--显示结果
/*
id name age
----------- -------------------- ----------
1 107863451
2 437576597
3 789577851
4 853578079
5 863342140
6 1172199226
7 1368391944
8 1538104520
9 1556200594
10 1579152671
11 1634104862
12 1671677003
13 1712061185
14 1805965510
15 1944393996
16 1960394053
17 2026490298
18 2058490412
19 2063346415
20 2099538563
21 2114106572
22 @begin_date 495340829
23 @BranchCD 1538104520
24 @bz 495340829
25 @cand 323532236
26 @collength 1235535485
27 @coltype 1235535485
28 @content 323532236
29 @datetime 2026490298
30 @definition 373576369
31 @definition 405576483
32 @diagramname 341576255
33 @diagramname 357576312
34 @diagramname 373576369
35 @diagramname 389576426
36 @diagramname 405576483
37 @diagramname 421576540
38 @EmpID 1669580986
39 @end_date 495340829
40 @id 789577851
41 @id 853578079
42 @id 1168723216
43 @id 1172199226
44 @ID 1368391944
45 @id 1712061185
46 @id1 1805965510
47 @id2 1805965510
48 @ip 863342140
49 @mingcheng 1944393996
50 @mingcheng 1960394053
51 @n 1556200594
52 @n 1579152671
53 @n 1634104862
54 @n 1671677003
55 @n 2114106572
56 @n1 1579152671
57 @n2 1579152671
58 @new_diagramname 389576426
59 @NUM 688057537
60 @option 323532236
61 @owner_id 341576255
62 @owner_id 357576312
63 @owner_id 373576369
64 @owner_id 389576426
65 @owner_id 405576483
66 @owner_id 421576540
67 @s 531532977
68 @s 1530488531
69 @s 2099538563
70 @split 531532977
71 @tablename 1235535485
72 @topic 323532236
73 @uid 323532236
74 @version 373576369
75 @version 405576483
76 @WEI 688057537
77 a 556581071
78 a 572581128
79 a 1440060216
80 A 1608392799
81 A1 273436048
82 A2 273436048
83 adddate 1946490013
84 adddate 2000062211
85 addr 69
86 address 1267535599
87 address 1504060444
88 age 672721449
89 age 812581983
90 aid 978818549
91 algorithm 95
92 audit_spec_id 59
93 auid 7
94 b 556581071
95 b 572581128
96 B 1608392799
97 B1 289436105
98 B2 289436105
99 backuplsn 24
100 batchsize 25(100 行受影响)*/
AS
INSERT INTO T1(name,age)
SELECT TOP 100 @name,@age
FROM master.dbo.spt_values;
GO
(@x nvarchar(20),@y int)
as
set nocount on
declare @str int
set @str=1
while @str<101
begin
insert into t1(name,age) value(@x,@y)
set @str=@str+1
end
set nocount off
declare @i int
set @i=1
while @i<=100
begin
insert into T1(name,age) values(@i, @i+1)
set @i=@i+1
end
CREATE PROC 存储过程
(
@name VARCHAR(20),
@age VARCHAR(10)
)
AS
SET NOCOUNT ON
DECLARE @i INT
SET @i=1
WHILE @i<101
BEGIN
INSERT INTO t1(name,age) value(@name,@age)
SET @i=@i+1
END
drop table T1
create table T1
(
id int identity(1,1) primary key,
name varchar(20),
age int
)if object_id('promm','P') is not null
drop procedure promm
gocreate procedure promm
as
declare @i int
set @i=1
while @i<101
begin
insert into T1(name,age)values('x',23)
set @i=@i+1
end
exec promm
select * from T1