IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'picseo')
	DROP DATABASE [picseo]
GO

Create Database [picseo]
 go
use [picseo]
 go

exec sp_addlogin 'picseo','picseo','picseo'
 go
exec sp_adduser 'picseo','picseo','db_owner'
 go
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Register]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Register]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[admin]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[admin]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[article]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[article]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[article2]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[article2]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[article_info]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[article_info]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[article_info2]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[article_info2]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[class]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[class]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[class2]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[class2]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[const]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[const]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[mb]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[mb]
GO

if not exists (select * from dbo.sysusers where name = N'picseo' and uid < 16382)
	EXEC sp_grantdbaccess N'picseo', N'picseo'
GO

exec sp_addrolemember N'db_owner', N'picseo'
GO

CREATE TABLE [dbo].[Register] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[Domain] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[BeginTime] [datetime] NULL ,
	[EndTime] [datetime] NULL ,
	[Cryptograph] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[admin] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[UserName] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[password] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[LastLoginIP] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[LastLogin] [datetime] NULL ,
	[Flag] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[article] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[picsName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[picsClass] [int] NULL ,
	[picsPath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[picsCover] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[picsCount] [int] NULL ,
	[author] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[Intime] [datetime] NULL ,
	[flag] [int] NULL ,
	[hit] [float] NULL ,
	[good] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[article2] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[picsName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[picsClass] [int] NULL ,
	[picsPath] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[picsCover] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[picsCount] [int] NULL ,
	[author] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[Intime] [datetime] NULL ,
	[flag] [int] NULL ,
	[hit] [float] NULL ,
	[good] [int] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[article_info] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[picsid] [int] NULL ,
	[title] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[mark] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
	[src] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[flag] [int] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[article_info2] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[picsid] [int] NULL ,
	[title] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[mark] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
	[src] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[flag] [int] NULL 
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[class] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[ClassName] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[ownerid] [int] NULL ,
	[ClassNameE] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[class2] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[ClassName] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[ownerid] [int] NULL ,
	[ClassNameE] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[const] (
	[ID] [int] IDENTITY (1, 1) NOT NULL ,
	[NetName] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[NetUrl] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[NetEmail] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[NetEmailPsw] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL ,
	[NetPostOffice] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[mb] (
	[id] [int] IDENTITY (1, 1) NOT NULL  ,
	[sy] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
	[lb] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
	[tj] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
	[dt] [ntext] COLLATE Chinese_PRC_CI_AS NULL ,
	[mbname] [nvarchar] (300) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[Register] ADD 
	CONSTRAINT [PK_Register] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[admin] ADD 
	CONSTRAINT [PK_admin] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[article] ADD 
	CONSTRAINT [DF_article_flag] DEFAULT (0) FOR [flag],
	CONSTRAINT [DF_article_hit] DEFAULT (0) FOR [hit],
	CONSTRAINT [DF_article_good] DEFAULT (0) FOR [good],
	CONSTRAINT [PK_article] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[article2] ADD 
	CONSTRAINT [DF_article2_flag] DEFAULT (0) FOR [flag],
	CONSTRAINT [DF_article2_hit] DEFAULT (0) FOR [hit],
	CONSTRAINT [DF_article2_good] DEFAULT (0) FOR [good],
	CONSTRAINT [PK_article2] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[article_info] ADD 
	CONSTRAINT [DF_article_info_flag] DEFAULT (0) FOR [flag],
	CONSTRAINT [PK_article_info] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[article_info2] ADD 
	CONSTRAINT [DF_article_info2_flag] DEFAULT (0) FOR [flag],
	CONSTRAINT [PK_article_info2] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[class] ADD 
	CONSTRAINT [DF_class_ownerid] DEFAULT (0) FOR [ownerid],
	CONSTRAINT [PK_class] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[class2] ADD 
	CONSTRAINT [DF_class2_ownerid] DEFAULT (0) FOR [ownerid],
	CONSTRAINT [PK_class2] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[const] ADD 
	CONSTRAINT [PK_const] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[mb] ADD 
	CONSTRAINT [PK_mb] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

