SQL
--创建范例学生表 CREATE TABLE Student ( StuId UNIQUEIDENTIFIER, StuName VARCHAR(10), Age INT, Phone VARCHAR(20) ) GO --新增(主键是随机数) INSERT INTO Student(StuId,StuName,Age,Phone)VALUES(NEWID(),'yhz',25,'150xxxxxxxxxxx') --删除一列(删除UNIQUEIDENTIFIER类型的列) ALTER TABLE student DROP COLUMN StuId --新增一列(新增varchar类型的StuId列) ALTER TABLE Student ADD Stuid VARCHAR(20) --修改表的数据类型(将StuId列的数据类型改为int) ALTER TABLE student ALTER COLUMN Stuid INT NOT NULL --添加主键约束 ALTER TABLE student ADD CONSTRAINT primarykey PRIMARY KEY(stuid)
---随机抽奖 砸金蛋游戏
SELECT *
FROM GameAward A
WHERE Amount > 0
AND GameInteractionID = 558
AND 3 > ISNULL(
(
SELECT SUM(Amount)
FROM GameAward
WHERE A.GameInteractionID = GameInteractionID
AND GameAwardID < A.GameAwardID
),
0
)
AND 3 <= ISNULL(
(
SELECT SUM(Amount)
FROM GameAward
WHERE A.GameInteractionID = GameInteractionID
AND GameAwardID <= A.GameAwardID
),
0
)