SQL ΪÖ÷±íµÄıһÌõ¼Ç¼£¬ÔÚÖмä±íÖÐͬʱ²åÈë¶àÌõÊý¾Ý
ÓÐʱÎÒÃÇ»áÏñÏÂÃæµÄÇé¿öÒ»Ñù£¬ÎªÖ÷±íµÄıһÌõ¼Ç¼£¬ÔÚÖмä±í(T_Stud_Course ±í)ÖÐͬʱ²åÈë¶àÌõÊý¾Ý
T_Student ±í
Stud_ID
Name
1
Tom
2
Jack
T_Course ±í
Course_ID
Course
1
Chinese
2
English
T_Stud_Course ±í
ID
Stud_ID
Course_ID
1
1
1
2
1
2
3
2
2
ÏÖÔÚÎÒÃÇ¿ÉÒÔÏÂÃæµÄ´æ´¢¹ý³ÌÀ´ÊµÏÖ£º
--ΪÖ÷±íµÄıһÌõ¼Ç¼£¬ÔÚÖмä±íÖÐͬʱ²åÈë¶àÌõÊý¾Ý
ALTER proc [dbo].[wholeInsert]
(
@insert_val nvarchar(1000), --ÐÂÔöµÄµÚÒ»¸ö×ֶεÄÖµ£¨¶à¸öÓÑ,’·Ö¸ô£©,ÈçA,B,
@PK_id nvarchar(50), --ÐÂÔöÊý¾ÝµÄµÚ¶þ¸ö×Ö¶ÎÖµ,ͬʱҲÊÇɾ³ý¾ÉÊý¾ÝµÄÌõ¼þ(²»Ö§³Ö¶à¸ö)
@col_1 nvarchar(20), --µÚÒ»¸ö×Ö¶ÎÃû
@col_2 nvarchar(20), --µÚ¶þ¸ö×Ö¶ÎÃû
@Tab nvarchar(20), --±íÃû
)
as
begin
declare @sql varchar(1000)
declare @strVal nvarchar(100)
set @sql='delete from '+@Tab+' where '+@col_2+'='+@PK_id
exec(@sql)
while(len(@insert_val)>0)
begin
set @strVal=substring(@insert_val,1,charindex(',',@insert_val,1)-1)
set @insert_val=substring(@insert_val,charindex(',',@insert_val,1)+1,len(@insert_val)-charindex(',',@insert_val,1))
set @sql='insert into '+@Tab+' ('+@col_1+','+@col_2+') values ('+@strVal+','+@PK_id+')'
exec(@sql)
end
end
Ö´ÐÐ:
Exec wholeInsert '1,2,','1','Course_ID','Stud_ID','T_Stud_Course'
--±íʾͬʱΪStud_ID=1µÄѧÉúÔö¼ÓÁ½ÃſγÌ(Course_IDΪ1ºÍ2)
Ïà¹ØÎĵµ£º
sql server³öÏÖÑ¡¶¨µÄÓû§ÓµÓжÔÏó¶øÎÞ·¨É¾³ýµÄ´¦Àí
2006-4-5 19:50:00
·½·¨Ò»
Ê×ÏÈÄãÐèÒª×öµÄµÚÒ»¼þÊÂ
ÆóÒµ¹ÜÀíÆ÷-¡µÑ¡Ôñ·þÎñÆ÷-¡µÊô***-¡µ·þÎñÆ÷ÉèÖÃ-¡µÌôÉÏÔÊÐí¶ÔϵͳĿ¼¡£¡£¡£-¡µÈ·¶¨
µÚ¶þ²½
ÕÒµ½ÄãµÄÊý¾Ý¿âÕÒµ½sysusers±íÄÇÄãÒÔÇ°µÄÓû§É¾³ý
µÚÈý²½»ØÈ¥°ÉÊô***Öµ¸Ä»ØÀ´
µÚËIJ¿Öؽ¨Óû§¼´¿É
·½·¨¶þ
¶ ......
1¡¢²éѯÁ½¸öʱ¼äÖ®¼ä
select * from [tablename] where date between \'value1\' and \'value2\'
2¡¢ÏÔʾ×îºó»Ø¸´Ê±¼ä
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
3¡¢Èճ̰²ÅÅÌáÇ°5·ÖÖÓÌáÐÑ
select * from Èճ̰²ÅÅ w ......
·ÖÒ³²éѯµÄÔÀí£º
Õâ¸öÖ»ÄÜÓÃÔÙSql2005¼°ÒÔÉϵİ汾
DECLARE @pagenum AS INT, @pagesize AS INT
SET @pagenum = 2
SET @pagesize = 3
SELECT *
from (SELECT ROW_NUMBER()&n ......
--ºÏ²¢ÐУ¬²¢·µ»ØºÏ²¢µÄÖµ
Create proc [dbo].[proUniteRow]
@tab varchar(30), --±íÃû
@col varchar(30), --ºÏ²¢µÄÁÐÃû
@where varchar(2000), &nbs ......