如何为新的WordPress安装创建MS SQL表?

时间:2014-04-06 20:07:37

标签: sql sql-server wordpress

我正在开发一个新的WordPress网站,为我的出版公司主办一个在线书店。由于我是.NET开发人员,我宁愿将MS SQL与WP DB Abstraction(https://wordpress.org/plugins/wordpress-database-abstraction/)插件结合使用。我做了全新安装的Brandoo Wordpress(http://www.microsoft.com/web/gallery/brandoowordpressmssql.aspx),效果很好。当我想创建数据库的副本以便我可以创建另一个WordPress实例时,我遇到了问题,因为没有复制与表结构,键,约束和默认值相关的所有细节。

在MS SQL Server中创建所有与WordPress相关的表需要什么CREATE TABLE语句?

1 个答案:

答案 0 :(得分:2)

对于SQL Server 2012,以下SQL脚本为WordPress 3.8.1创建了所有必需的表。

USE [WordPressDb]
GO

/****** Object:  Table [dbo].[wp_commentmeta]    Script Date: 4/6/2014 5:35:46 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_commentmeta](
    [meta_id] [bigint] IDENTITY(1,1) NOT NULL,
    [comment_id] [bigint] NOT NULL,
    [meta_key] [nvarchar](255) NULL,
    [meta_value] [nvarchar](max) NULL,
 CONSTRAINT [wp_commentmeta_meta_id] PRIMARY KEY CLUSTERED 
(
    [meta_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_commentmeta] ADD  DEFAULT ('0') FOR [comment_id]
GO

ALTER TABLE [dbo].[wp_commentmeta] ADD  DEFAULT (NULL) FOR [meta_key]
GO

/****** Object:  Table [dbo].[wp_comments]    Script Date: 4/6/2014 5:37:04 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_comments](
    [comment_ID] [bigint] IDENTITY(1,1) NOT NULL,
    [comment_post_ID] [bigint] NOT NULL,
    [comment_author] [nvarchar](max) NOT NULL,
    [comment_author_email] [nvarchar](100) NOT NULL,
    [comment_author_url] [nvarchar](200) NOT NULL,
    [comment_author_IP] [nvarchar](100) NOT NULL,
    [comment_date] [datetime] NOT NULL,
    [comment_date_gmt] [datetime] NOT NULL,
    [comment_content] [nvarchar](max) NOT NULL,
    [comment_karma] [int] NOT NULL,
    [comment_approved] [nvarchar](20) NOT NULL,
    [comment_agent] [nvarchar](255) NOT NULL,
    [comment_type] [nvarchar](20) NOT NULL,
    [comment_parent] [bigint] NOT NULL,
    [user_id] [bigint] NOT NULL,
 CONSTRAINT [wp_comments_comment_ID] PRIMARY KEY CLUSTERED 
(
    [comment_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('0') FOR [comment_post_ID]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('') FOR [comment_author_email]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('') FOR [comment_author_url]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('') FOR [comment_author_IP]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT (getdate()) FOR [comment_date]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT (getdate()) FOR [comment_date_gmt]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('0') FOR [comment_karma]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('1') FOR [comment_approved]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('') FOR [comment_agent]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('') FOR [comment_type]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('0') FOR [comment_parent]
GO

ALTER TABLE [dbo].[wp_comments] ADD  DEFAULT ('0') FOR [user_id]
GO

/****** Object:  Table [dbo].[wp_links]    Script Date: 4/6/2014 5:37:25 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_links](
    [link_id] [bigint] IDENTITY(1,1) NOT NULL,
    [link_url] [nvarchar](255) NOT NULL,
    [link_name] [nvarchar](255) NOT NULL,
    [link_image] [nvarchar](255) NOT NULL,
    [link_target] [nvarchar](25) NOT NULL,
    [link_description] [nvarchar](255) NOT NULL,
    [link_visible] [nvarchar](20) NOT NULL,
    [link_owner] [bigint] NOT NULL,
    [link_rating] [int] NOT NULL,
    [link_updated] [datetime] NOT NULL,
    [link_rel] [nvarchar](255) NOT NULL,
    [link_notes] [nvarchar](max) NOT NULL,
    [link_rss] [nvarchar](255) NOT NULL,
 CONSTRAINT [wp_links_link_id] PRIMARY KEY CLUSTERED 
(
    [link_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('') FOR [link_url]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('') FOR [link_name]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('') FOR [link_image]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('') FOR [link_target]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('') FOR [link_description]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('Y') FOR [link_visible]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('1') FOR [link_owner]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('0') FOR [link_rating]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT (getdate()) FOR [link_updated]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('') FOR [link_rel]
GO

ALTER TABLE [dbo].[wp_links] ADD  DEFAULT ('') FOR [link_rss]
GO

/****** Object:  Table [dbo].[wp_options]    Script Date: 4/6/2014 5:38:02 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_options](
    [option_id] [bigint] IDENTITY(1,1) NOT NULL,
    [option_name] [nvarchar](64) NOT NULL,
    [option_value] [nvarchar](max) NOT NULL,
    [autoload] [nvarchar](20) NOT NULL,
 CONSTRAINT [wp_options_option_id] PRIMARY KEY CLUSTERED 
(
    [option_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
 CONSTRAINT [wp_options_option_name] UNIQUE NONCLUSTERED 
(
    [option_name] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_options] ADD  DEFAULT ('') FOR [option_name]
GO

ALTER TABLE [dbo].[wp_options] ADD  DEFAULT ('yes') FOR [autoload]
GO


/****** Object:  Table [dbo].[wp_postmeta]    Script Date: 4/6/2014 5:38:19 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_postmeta](
    [meta_id] [bigint] IDENTITY(1,1) NOT NULL,
    [post_id] [bigint] NOT NULL,
    [meta_key] [nvarchar](255) NULL,
    [meta_value] [nvarchar](max) NULL,
 CONSTRAINT [wp_postmeta_meta_id] PRIMARY KEY CLUSTERED 
(
    [meta_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_postmeta] ADD  DEFAULT ('0') FOR [post_id]
GO

ALTER TABLE [dbo].[wp_postmeta] ADD  DEFAULT (NULL) FOR [meta_key]
GO


/****** Object:  Table [dbo].[wp_posts]    Script Date: 4/6/2014 5:38:37 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_posts](
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [post_author] [bigint] NOT NULL,
    [post_date] [datetime] NOT NULL,
    [post_date_gmt] [datetime] NOT NULL,
    [post_content] [nvarchar](max) NOT NULL,
    [post_title] [nvarchar](max) NOT NULL,
    [post_excerpt] [nvarchar](max) NOT NULL,
    [post_status] [nvarchar](20) NOT NULL,
    [comment_status] [nvarchar](20) NOT NULL,
    [ping_status] [nvarchar](20) NOT NULL,
    [post_password] [nvarchar](20) NOT NULL,
    [post_name] [nvarchar](200) NOT NULL,
    [to_ping] [nvarchar](max) NOT NULL,
    [pinged] [nvarchar](max) NOT NULL,
    [post_modified] [datetime] NOT NULL,
    [post_modified_gmt] [datetime] NOT NULL,
    [post_content_filtered] [nvarchar](max) NOT NULL,
    [post_parent] [bigint] NOT NULL,
    [guid] [nvarchar](255) NOT NULL,
    [menu_order] [int] NOT NULL,
    [post_type] [nvarchar](20) NOT NULL,
    [post_mime_type] [nvarchar](100) NOT NULL,
    [comment_count] [bigint] NOT NULL,
 CONSTRAINT [wp_posts_ID] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('0') FOR [post_author]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT (getdate()) FOR [post_date]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT (getdate()) FOR [post_date_gmt]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('publish') FOR [post_status]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('open') FOR [comment_status]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('open') FOR [ping_status]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('') FOR [post_password]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('') FOR [post_name]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT (getdate()) FOR [post_modified]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT (getdate()) FOR [post_modified_gmt]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('0') FOR [post_parent]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('') FOR [guid]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('0') FOR [menu_order]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('post') FOR [post_type]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('') FOR [post_mime_type]
GO

ALTER TABLE [dbo].[wp_posts] ADD  DEFAULT ('0') FOR [comment_count]
GO

/****** Object:  Table [dbo].[wp_term_relationships]    Script Date: 4/6/2014 5:38:54 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_term_relationships](
    [object_id] [bigint] NOT NULL,
    [term_taxonomy_id] [bigint] NOT NULL,
    [term_order] [int] NOT NULL,
 CONSTRAINT [wp_term_relationships_object_id_term_taxonomy_id] PRIMARY KEY CLUSTERED 
(
    [object_id] ASC,
    [term_taxonomy_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_term_relationships] ADD  DEFAULT ((0)) FOR [object_id]
GO

ALTER TABLE [dbo].[wp_term_relationships] ADD  DEFAULT ((0)) FOR [term_taxonomy_id]
GO

ALTER TABLE [dbo].[wp_term_relationships] ADD  DEFAULT ((0)) FOR [term_order]
GO


/****** Object:  Table [dbo].[wp_term_taxonomy]    Script Date: 4/6/2014 5:39:09 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_term_taxonomy](
    [term_taxonomy_id] [bigint] IDENTITY(1,1) NOT NULL,
    [term_id] [bigint] NOT NULL,
    [taxonomy] [nvarchar](32) NOT NULL,
    [description] [nvarchar](max) NOT NULL,
    [parent] [bigint] NOT NULL,
    [count] [bigint] NOT NULL,
 CONSTRAINT [wp_term_taxonomy_term_taxonomy_id] PRIMARY KEY CLUSTERED 
(
    [term_taxonomy_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_term_taxonomy] ADD  DEFAULT ((0)) FOR [term_id]
GO

ALTER TABLE [dbo].[wp_term_taxonomy] ADD  DEFAULT ('') FOR [taxonomy]
GO

ALTER TABLE [dbo].[wp_term_taxonomy] ADD  DEFAULT ((0)) FOR [parent]
GO

ALTER TABLE [dbo].[wp_term_taxonomy] ADD  DEFAULT ((0)) FOR [count]
GO


/****** Object:  Table [dbo].[wp_terms]    Script Date: 4/6/2014 5:39:27 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_terms](
    [term_id] [bigint] IDENTITY(1,1) NOT NULL,
    [name] [nvarchar](200) NOT NULL,
    [slug] [nvarchar](200) NOT NULL,
    [term_group] [bigint] NOT NULL,
 CONSTRAINT [wp_terms_term_id] PRIMARY KEY CLUSTERED 
(
    [term_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_terms] ADD  DEFAULT ('') FOR [name]
GO

ALTER TABLE [dbo].[wp_terms] ADD  DEFAULT ('') FOR [slug]
GO

ALTER TABLE [dbo].[wp_terms] ADD  DEFAULT ((0)) FOR [term_group]
GO


/****** Object:  Table [dbo].[wp_usermeta]    Script Date: 4/6/2014 5:39:41 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_usermeta](
    [umeta_id] [bigint] IDENTITY(1,1) NOT NULL,
    [user_id] [bigint] NOT NULL,
    [meta_key] [nvarchar](255) NULL,
    [meta_value] [nvarchar](max) NULL,
 CONSTRAINT [wp_usermeta_umeta_id] PRIMARY KEY CLUSTERED 
(
    [umeta_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_usermeta] ADD  DEFAULT ('0') FOR [user_id]
GO

ALTER TABLE [dbo].[wp_usermeta] ADD  DEFAULT (NULL) FOR [meta_key]
GO


/****** Object:  Table [dbo].[wp_users]    Script Date: 4/6/2014 5:39:57 PM ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[wp_users](
    [ID] [bigint] IDENTITY(1,1) NOT NULL,
    [user_login] [nvarchar](60) NOT NULL,
    [user_pass] [nvarchar](64) NOT NULL,
    [user_nicename] [nvarchar](50) NOT NULL,
    [user_email] [nvarchar](100) NOT NULL,
    [user_url] [nvarchar](100) NOT NULL,
    [user_registered] [datetime] NOT NULL,
    [user_activation_key] [nvarchar](60) NOT NULL,
    [user_status] [int] NOT NULL,
    [display_name] [nvarchar](250) NOT NULL,
 CONSTRAINT [wp_users_ID] PRIMARY KEY CLUSTERED 
(
    [ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('') FOR [user_login]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('') FOR [user_pass]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('') FOR [user_nicename]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('') FOR [user_email]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('') FOR [user_url]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT (getdate()) FOR [user_registered]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('') FOR [user_activation_key]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('0') FOR [user_status]
GO

ALTER TABLE [dbo].[wp_users] ADD  DEFAULT ('') FOR [display_name]
GO