您的位置: 旅游网 > 情感

谈SQL Server 2005中的T-SQL增强(3)

发布时间:2019-09-13 20:40:41

3、代码演示 USE demoGOCREATE TABLE tt(id INT IDENTITY,c1 VARCHAR(15))GOINSERT INTO tt VALUES ('r1')INSERT INTO tt VALUES ('r2')INSERT INTO tt VALUES ('r5')INSERT INTO tt VALUES ('r6')INSERT INTO tt VALUES ('r7')INSERT INTO tt VALUES ('r8')INSERT INTO tt VALUES ('r9')INSERT INTO tt VALUES ('r10')DECLARE @del AS TABLE (deletedId INT, deletedValue VARCHAR(15))DELETE ttOUTPUT DELETED.id, DELETED.c1 INTO @delWHERE id < 3SELECT * FROM @delGO-----------------------------------------------USE demoGOCREATE TABLE toptest (column1 VARCHAR(150))GOINSERT INTO toptest VALUES('t1')INSERT INTO toptest VALUES('t2')INSERT INTO toptest VALUES('t3')INSERT INTO toptest VALUES('t4')INSERT INTO toptest VALUES('t5')INSERT INTO toptest VALUES('t6')INSERT INTO toptest VALUES('t7')INSERT INTO toptest VALUES('t8')SELECT * FROM toptestGOCREATE TABLE toptest2 (column2 VARCHAR(150))GOINSERT INTO toptest2 VALUES('c1')INSERT INTO toptest2 VALUES('c2')--声明3个变量DECLARE @a INTDECLARE @b INTDECLARE @c INT--赋值SET @a = 10SET @b = 5SELECT @c = @a/@b--使用计算表达式SELECT TOP(@c) * FROM toptest--使用SELECT语句作为条件SELECT TOP(SELECT COUNT(*) FROM toptest2) *FROM toptest--指出topDELETE TOP(2) toptest where column1>'t6'--更新topUPDATE TOP(2) toptest SET column1 = 'hi' where column1<='t2'SELECT * FROM toptest

薏芽健脾凝胶疗程
薏芽健脾凝胶
尿不尽中药调理
小孩子经常流鼻血是怎么回事
猜你会喜欢的
猜你会喜欢的