📄 cs_procedures.sql
字号:
--## END Schema Patch ##
Insert into cs_SchemaVersion(Major, Minor, Patch, InstallDate) values (@Major, @Minor, @Patch, GetDate())
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was applied successfully '
END
ELSE IF(@Installed is not null)
BEGIN
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was already applied on ' + Convert(varchar(50), @Installed)
END
ELSE
BEGIN
Print 'The patch could not be applied because your current schema is missing previous updates (Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ')'
END
/***********************************************
* Patch: cs_Schema_Patch_2.1.12
* File Date: 8/8/2006 10:57:08 AM
***********************************************/
Print 'Creating...cs_Schema_Patch_2.1.12'
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DECLARE @Major int, @Minor int, @Patch int, @Installed DateTime, @Prereqs int
Set @Major = 2;
Set @Minor = 1;
Set @Patch = 12;
Select @Prereqs = isnull(Count(InstallDate),0) from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch<@Patch
Select @Installed = InstallDate from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch=@Patch
If(@Installed is null AND @Prereqs = @Patch)
BEGIN
--## Schema Patch ##
update cs_Posts Set PostName = Replace(PostName,'_',' ') where PostName is not null
--## END Schema Patch ##
Insert into cs_SchemaVersion(Major, Minor, Patch, InstallDate) values (@Major, @Minor, @Patch, GetDate())
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was applied successfully '
END
ELSE IF(@Installed is not null)
BEGIN
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was already applied on ' + Convert(varchar(50), @Installed)
END
ELSE
BEGIN
Print 'The patch could not be applied because your current schema is missing previous updates (Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ')'
END
/***********************************************
* Patch: cs_Schema_Patch_2.1.13
* File Date: 8/8/2006 10:57:08 AM
***********************************************/
Print 'Creating...cs_Schema_Patch_2.1.13'
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DECLARE @Major int, @Minor int, @Patch int, @Installed DateTime, @Prereqs int
Set @Major = 2;
Set @Minor = 1;
Set @Patch = 13;
Select @Prereqs = isnull(Count(InstallDate),0) from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch<@Patch
Select @Installed = InstallDate from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch=@Patch
If(@Installed is null AND @Prereqs = @Patch)
BEGIN
--## Schema Patch ##
exec sp_ExecuteSQL N'CREATE TABLE [dbo].[cs_UserInvitation] (
[InvitationKey] uniqueidentifier ROWGUIDCOL NOT NULL ,
[UserID] [int] NOT NULL ,
[Email] [nvarchar] (255) NOT NULL ,
[DateInvited] [datetime] NOT NULL
) ON [PRIMARY]'
exec sp_ExecuteSQL N'ALTER TABLE [dbo].[cs_UserInvitation] WITH NOCHECK ADD
CONSTRAINT [PK_cs_UserInvitation] PRIMARY KEY CLUSTERED
(
[InvitationKey]
) ON [PRIMARY]'
exec sp_ExecuteSQL N'ALTER TABLE [dbo].[cs_UserInvitation] ADD
CONSTRAINT [DF_cs_UserInvitation_InvitationKey] DEFAULT (newid()) FOR [InvitationKey],
CONSTRAINT [DF_cs_UserInvitation_DateInvited] DEFAULT (getdate()) FOR [DateInvited]'
exec sp_ExecuteSQL N'ALTER TABLE dbo.cs_UserInvitation ADD
PropertyNames ntext NULL,
PropertyValues ntext NULL'
--## END Schema Patch ##
Insert into cs_SchemaVersion(Major, Minor, Patch, InstallDate) values (@Major, @Minor, @Patch, GetDate())
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was applied successfully '
END
ELSE IF(@Installed is not null)
BEGIN
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was already applied on ' + Convert(varchar(50), @Installed)
END
ELSE
BEGIN
Print 'The patch could not be applied because your current schema is missing previous updates (Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ')'
END
/***********************************************
* Patch: cs_Schema_Patch_2.1.14
* File Date: 8/8/2006 10:57:08 AM
***********************************************/
Print 'Creating...cs_Schema_Patch_2.1.14'
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DECLARE @Major int, @Minor int, @Patch int, @Installed DateTime, @Prereqs int
Set @Major = 2;
Set @Minor = 1;
Set @Patch = 14;
Select @Prereqs = isnull(Count(InstallDate),0) from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch<@Patch
Select @Installed = InstallDate from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch=@Patch
If(@Installed is null AND @Prereqs = @Patch)
BEGIN
--## Schema Patch ##
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[csm_Sections_MailingLists_Delete]') and OBJECTPROPERTY(id, N'IsTrigger') = 1)
begin
exec sp_ExecuteSQL N'CREATE TRIGGER csm_Sections_MailingLists_Delete ON cs_Sections
FOR DELETE
AS
BEGIN
DELETE FROM csm_MailingLists WHERE SectionID IN (SELECT SectionID FROM DELETED)
DELETE FROM csm_EmailIds WHERE SectionID IN (SELECT SectionID FROM DELETED)
END'
end
--## END Schema Patch ##
Insert into cs_SchemaVersion(Major, Minor, Patch, InstallDate) values (@Major, @Minor, @Patch, GetDate())
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was applied successfully '
END
ELSE IF(@Installed is not null)
BEGIN
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was already applied on ' + Convert(varchar(50), @Installed)
END
ELSE
BEGIN
Print 'The patch could not be applied because your current schema is missing previous updates (Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ')'
END
/***********************************************
* Patch: cs_Schema_Patch_2.1.15
* File Date: 8/8/2006 10:57:08 AM
***********************************************/
Print 'Creating...cs_Schema_Patch_2.1.15'
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DECLARE @Major int, @Minor int, @Patch int, @Installed DateTime, @Prereqs int
Set @Major = 2;
Set @Minor = 1;
Set @Patch = 15;
Select @Prereqs = isnull(Count(InstallDate),0) from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch<@Patch
Select @Installed = InstallDate from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch=@Patch
If(@Installed is null AND @Prereqs = @Patch)
BEGIN
--## Schema Patch ##
/***************************************** This has been moved to an addon ********************************************
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_RssCtrl]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
exec sp_ExecuteSQL N'CREATE TABLE [dbo].[cs_RssCtrl] (
[CtrlID] [int] NOT NULL ,
[Title] [varchar] (256) NOT NULL ,
[Name] [varchar] (256) NOT NULL ,
[ExerptSize] [int] NOT NULL ,
[PostCount] [int] NULL
) ON [PRIMARY]'
exec sp_ExecuteSQL N'ALTER TABLE [dbo].[cs_RssCtrl] ADD
CONSTRAINT [DF_RssCtrl_ExerptSize] DEFAULT (125) FOR [ExerptSize],
CONSTRAINT [DF_cs_RssCtrl_PostCount] DEFAULT (3) FOR [PostCount]'
exec sp_ExecuteSQL N'CREATE UNIQUE INDEX [IX_cs_RssCtrl] ON [dbo].[cs_RssCtrl]([CtrlID]) ON [PRIMARY]'
end
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_RssCtrlFeeds]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
exec sp_ExecuteSQL N'CREATE TABLE [dbo].[cs_RssCtrlFeeds] (
[CtrlID] [int] NOT NULL ,
[UrlID] [int] NOT NULL ,
[Enabled] [bit] NOT NULL ,
[Title] [nvarchar] (256) NOT NULL ,
[SubscribeDate] [datetime] NOT NULL ,
[LastUpdateDate] [datetime] NOT NULL ,
[LastModifiedDate] [datetime] NOT NULL ,
[ETag] [nvarchar] (256) NULL ,
[State] [int] NOT NULL
) ON [PRIMARY]'
exec sp_ExecuteSQL N'ALTER TABLE [dbo].[cs_RssCtrlFeeds] ADD
CONSTRAINT [DF_cs_RssCtrlFeeds_Enabled] DEFAULT (1) FOR [Enabled],
CONSTRAINT [DF_cs_RssCtrlFeeds_State] DEFAULT (0) FOR [State]'
exec sp_ExecuteSQL N'CREATE INDEX [IX_cs_RssCtrlFeeds] ON [dbo].[cs_RssCtrlFeeds]([CtrlID]) ON [PRIMARY]'
end
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_RssCtrlPost]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
exec sp_ExecuteSQL N'CREATE TABLE [dbo].[cs_RssCtrlPost] (
[PostID] [int] IDENTITY (1, 1) NOT NULL ,
[CtrlID] [int] NOT NULL ,
[UrlID] [int] NOT NULL ,
[Author] [nvarchar] (256) NOT NULL ,
[Subject] [nvarchar] (256) NULL ,
[Body] [ntext] NULL ,
[PostDate] [datetime] NOT NULL ,
[PermaLink] [nvarchar] (312) NOT NULL ,
[CommentUrl] [nvarchar] (512) NULL ,
[CommentCount] [int] NULL ,
[GuidName] [nvarchar] (512) NULL ,
[GuidIsPermaLink] [bit] NOT NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]'
exec sp_ExecuteSQL N'CREATE UNIQUE INDEX [IX_cs_RssCtrlPost] ON [dbo].[cs_RssCtrlPost]([PostID]) ON [PRIMARY]'
exec sp_ExecuteSQL N'CREATE INDEX [IX_cs_RssCtrlPost_1] ON [dbo].[cs_RssCtrlPost]([CtrlID]) ON [PRIMARY]'
-- Index is too big for SQL2000
--exec sp_ExecuteSQL N'CREATE UNIQUE INDEX [IX_cs_RssCtrlPost_2] ON [dbo].[cs_RssCtrlPost]([PermaLink]) ON [PRIMARY]'
end
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[cs_RssCtrlUrls]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
exec sp_ExecuteSQL N'CREATE TABLE [dbo].[cs_RssCtrlUrls] (
[UrlID] [int] IDENTITY (1, 1) NOT NULL ,
[Url] [nvarchar] (512) NOT NULL
) ON [PRIMARY]'
exec sp_ExecuteSQL N'CREATE UNIQUE INDEX [IX_cs_RssCtrlUrls] ON [dbo].[cs_RssCtrlUrls]([UrlID]) ON [PRIMARY]'
end
***********************************************************************************************************************************/
--## END Schema Patch ##
Insert into cs_SchemaVersion(Major, Minor, Patch, InstallDate) values (@Major, @Minor, @Patch, GetDate())
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was applied successfully '
END
ELSE IF(@Installed is not null)
BEGIN
Print 'Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ' was already applied on ' + Convert(varchar(50), @Installed)
END
ELSE
BEGIN
Print 'The patch could not be applied because your current schema is missing previous updates (Schema Patch v' + Convert(Varchar(2),@Major) + '.' + Convert(Varchar(2),@Minor) + '.' + Convert(Varchar(3),@Patch) + ')'
END
/***********************************************
* Patch: cs_Schema_Patch_2.1.16
* File Date: 8/8/2006 10:57:08 AM
***********************************************/
Print 'Creating...cs_Schema_Patch_2.1.16'
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
DECLARE @Major int, @Minor int, @Patch int, @Installed DateTime, @Prereqs int
Set @Major = 2;
Set @Minor = 1;
Set @Patch = 16;
Select @Prereqs = isnull(Count(InstallDate),0) from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch<@Patch
Select @Installed = InstallDate from cs_SchemaVersion where Major=@Major and Minor=@Minor and Patch=@Patch
If(@Installed is null AND @Prereqs = @Patch)
BEGIN
--## Schema Patch ##
DECLARE @TABLE_SCHEMA NVARCHAR(50),@TABLE_NAME NVARCHAR(50),@COLUMN_NAME NVARCHAR(50),@CONSTRAINT_NAME NVARCHAR(50)
SET @TABLE_SCHEMA = 'dbo'
SET @TABLE_NAME = 'cs_RollerBlogFeeds'
SET @COLUMN_NAME = 'IsRollerBlogAggregated'
SELECT
@CONSTRAINT_NAME = OBJECT_NAME(c1.cdefault)
FROM syscolumns AS c1
JOIN syscomments AS c2
ON c1.cdefault = c2.id
WHERE OBJECT_NAME(c1.id) = @TABLE_NAME AND c1.name = @COLUMN_NAME
/* the following does the same thing but is SQL 2005 only
select
@CONSTRAINT_NAME = d.name
from sys.default_constraints as d
join sys.objects as o
on o.object_id = d.parent_object_id
join sys.columns as c
on c.object_id = o.object_id and c.column_id = d.parent_column_id
join sys.schemas as s
on s.schema_id = o.schema_id
WHERE s.name = @TABLE_SCHEMA and o.name = @TABLE_NAME and c.name = @COLUMN_NAME
*/
DECLARE @STRSQL NVARCHAR(4000);
if @CONSTRAINT_NAME is not null
BEGIN
SELECT @STRSQL = N'ALTER TABLE [' + @TABLE_SCHEMA + '].['+ @TABLE_NAME +'] DROP CONSTRAINT ['+@CONSTRAINT_NAME+']'
exec sp_ExecuteSQL @STRSQL
END
if exists (select * from dbo.sysobjects where id = object_id(N'[' + @TABLE_SCHEMA + '].['+ @TABLE_NAME +']') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
SELECT @STRSQL = N'ALTER TABLE [' + @TABLE_SCHEMA + '].['+ @TABLE_NAME +'] DROP COLUMN ['+@COLUMN_NAME+']'
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -