Dreamweaver正则一例

时间:2010-12-13 阅读:
原始内容如下:
CREATE TABLE [dbo].[table1] (
)
GO
CREATE TABLE [dbo].[table2] (
)
GO
CREATE TABLE [dbo].[table3] (
)
GO
CREATE TABLE [dbo].[table4] (
)
GO
CREATE TABLE [dbo].[table5] (
)
GO
..........
指的是创建N个表,现在要求在创建前删除原来的表,格式如下
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_

原始内容如下:

CREATE TABLE [dbo].[table1] (
)
GO

CREATE TABLE [dbo].[table2] (
)
GO

CREATE TABLE [dbo].[table3] (
)
GO

CREATE TABLE [dbo].[table4] (
)
GO

CREATE TABLE [dbo].[table5] (
)
GO

..........

指的是创建N个表,现在要求在创建前删除原来的表,格式如下

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table1]') AND type in (N'U'))
BEGIN
    DROP TABLE [dbo].[table1]
END

CREATE TABLE [dbo].[table1] (
)
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table2]') AND type in (N'U'))
BEGIN
    DROP TABLE [dbo].[table2]
END
CREATE TABLE [dbo].[table2] (
)
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table3]') AND type in (N'U'))
BEGIN
    DROP TABLE [dbo].[table3]
END
CREATE TABLE [dbo].[table3] (
)
GO

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table4]') AND type in (N'U'))
BEGIN
    DROP TABLE [dbo].[table4]
END
CREATE TABLE [dbo].[table4] (
)
GO


IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[table5]') AND type in (N'U'))
BEGIN
    DROP TABLE [dbo].[table5]
END
CREATE TABLE [dbo].[table5] (
)
GO

 

逐个改太麻烦,此时可以时候一些辅助工具,这里我用Dreamweaver:

一、打开查找和替换;

二、在“查找”中填入

CREATE TABLE \[dbo\]\.\[([a-zA-Z0-9\_\-]+)\]

三、在替换中填入

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[$1]') AND type in (N'U'))
BEGIN
    DROP TABLE [dbo].[$1]
END
CREATE TABLE [dbo].[$1]

四、勾选“使用正则表达式”,然后点击“全部替换即可”。



 

[责任编辑:jumbot]

[发表评论] [收藏本页]