比特网
1 增加字段
IF NOT EXISTS (SELECT * FROM SYSCOLUMNS WHERE ID=OBJECT_ID('QueryDataSource') and name = 'IsCrossTable')
BEGIN
ALTER TABLE QueryDataSource ADD IsCrossTable bit default(0) --插入字段
END
2 存储过程
如果存在 (select * from dbo.sysobjects where id = object_id(N'[dbo].[PLSystem_Insert]') and OBJECTPROPERTY (id, N'IsProcedure') = 1)
删除过程 [dbo].[PLSystem_Insert]
go
CREATE PROCEDURE dbo.PLSystem_Insert
(
@PLSystemIDsmallint,
@ PLSystemName varchar(20),
@PLSystemFlag char(2)
)
AS
插入 dbo.PLSystem
(
PLSystemID,
PLSystemName,
PLSystemFlag
)
值
(
@PLSystemID,
@PLSystemName,
@PLSystemFlag
)
转到
如果存在(从 dbo.select * 中选择 *)。 sysobjects where id = object_id(N'[dbo].[PLSystem_Delete]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
删除过程 [dbo].[PLSystem_Delete]
go
CREATE PROCEDURE dbo.PLSystem_Delete
(
@PLSystemIDsmallint
)
AS
从 dbo.PLSystem 删除
WHERE
PLSystemID = @PLSystemID
go
if 存在 (select * from dbo.sysobjects where id = object_id(N'[dbo].[PLSystem_Update]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
删除过程 [dbo].[PLSystem_Update ]
去
创建过程 dbo.PLSystem_Update
(
@PLSystemID Smallint,
@PLSystemName varchar(20),
@PLSystemFlag char(2)
)
AS
UPDATE dbo.PLSystem SET
PLSystemName = @PLSystemName,
PLSystemFlag = @PLSystemFlag
WHERE
PLSystemID = @PLSystemID
go
3 个表
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[PLSystem]') AND type in (N'U'))
删除表 [dbo].[PLSystem ]
执行
如果不存在(从 sys.objects 中选择 *,其中 object_id = OBJECT_ID(N'[dbo].[PLSystem]') 并输入 (N'U'))
开始
CREATE TABLE [dbo].[PLSystem](
[PLSystemID] [tinyint] NOT NULL,
[PLSystemName] [varchar](20) NULL,
[PLSystemFlag] [char](2) NULL ,
约束 [XPKPLSystem] 主键集群
(
[PLSystemID] ASC
)
) ON [PRIMARY]
END
GO
4 游标
开始
声明 @PluserID varchar(8)
声明 pluserCurse 光标,用于从 PLUser 选择 PLUserID,其中 PCancelJudge=0
打开 pluserCurse --打开游标
从 pluserCurse 获取下一个内容到 @ PluserID
while @@FETCH_STATUS=0
开始
打印 (@PluserID)
插入 PLUserActorDepart(DepartID,PLActorSystemID,PLUserID)
从 MSUserRight 中选择 DepartmentID、PLSystemID、PLUserID,其中 MSUserRight.DepartmentID不在
(
从PLDepartment中选择DepartmentID,其中PLDepartment.DParent =(从PLUser中选择DepartmentID,其中PLUserID = @PluserID)
或PLDepartment.DepartmentID =(从PLUser中选择DepartmentID,其中PLUserID = @PluserID)
) AND MSUserRight.PLUserID=@PluserID
从 pluserCurse 中获取下一个内容到 @PluserID
end
关闭 pluserCurse
释放 pluserCurse
end
5 使用 while 实现循环
创建 Proc InsertSQL
AS
开始
DECLARE @Count int
set @Count=0;
同时(@Count开始
打印(@Count);
插入学生值('YOUNG','M',100,'FUJIANXIAMENT');
设置@Count=@Count 1;
END
END
bitsCN.com