名站网址导航为大家提供关于数据库教程相关的教程网站知识。
动态给表添加删除字段并同时修改它的插入更新存储过程
复制具体相关代码 具体相关代码如下:,CREATE PROCEDURE [dbo].[usp_B_DymanicallyAlterStoreProcedure] AS DECLARE @VariableList NVARChAR(MAX),复制具体相关代码 具体相关代码如下:,CREATE TRIGGER [dbo].[tri_A_Insert] ON [dbo].[A] FOR INSERT AS BEGIN SET NOCOUNT ON DECLARE @FieldNa,复制具体相关代码 具体相关代码如下:,CREATE TRIGGER [dbo].[tri_A_Delete] ON [dbo].[A] FOR DELETE AS BEGIN SET NOCOUNT ON DECLARE @FieldNa
复制具体相关代码 具体相关代码如下:
DECLARE @c INT
DECLARE @c2 INT
SELECT @c = COUNT(1)
FROM dbo.SplitToTable('1|2|3|4', '|')
SELECT @c2=COUNT(1)
FROM dbo.SplitToTable('1|2|3|4', '|') a
INNER JOIN dbo.SplitToTable('1|2|3|', '|') b ON a.value = b.value
IF @c = @c2
SELECT 'ok'
ELSE
SELECT 'no'
SplitToTable这个函数如下:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER FUNCTION [dbo].[SplitToTable]
(
@SplitString NVARChAR(MAX) ,
@Separator NVARChAR(10) = ' '
)
RETURNS @SplitStringsTable TABLE
(
[id] INT IDENTITY(1, 1) ,
[value] NVARChAR(MAX)
)
AS
BEGIN
DECLARE @CurrentIndex INT ;
DECLARE @NextIndex INT ;
DECLARE @ReturnText NVARChAR(MAX) ;
SELECT @CurrentIndex = 1 ;
WhILE ( @CurrentIndex <= LEN(@SplitString) )
BEGIN
SELECT @NextIndex = ChARINDEX(@Separator, @SplitString,
@CurrentIndex) ;
IF ( @NextIndex = 0
OR @NextIndex IS NULL
)
SELECT @NextIndex = LEN(@SplitString) 1 ;
SELECT @ReturnText = SUBSTRING(@SplitString,
@CurrentIndex,
@NextIndex - @CurrentIndex) ;
INSERT INTO @SplitStringsTable
( [value] )
VALUES ( @ReturnText ) ;
SELECT @CurrentIndex = @NextIndex 1 ;
END
RETURN ;
END