/****** Object:  Database tongxunlu    Script Date: 2007-4-3 16:23:52 ******/
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'tongxunlu')
	DROP DATABASE [tongxunlu]
GO

CREATE DATABASE [tongxunlu]  ON (NAME = N'tongxunlu_Data', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\tongxunlu_Data.MDF' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'tongxunlu_Log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL\data\tongxunlu_Log.LDF' , SIZE = 1, FILEGROWTH = 10%)
 COLLATE Chinese_PRC_CI_AS
GO

exec sp_dboption N'tongxunlu', N'autoclose', N'true'
GO

exec sp_dboption N'tongxunlu', N'bulkcopy', N'false'
GO

exec sp_dboption N'tongxunlu', N'trunc. log', N'true'
GO

exec sp_dboption N'tongxunlu', N'torn page detection', N'true'
GO

exec sp_dboption N'tongxunlu', N'read only', N'false'
GO

exec sp_dboption N'tongxunlu', N'dbo use', N'false'
GO

exec sp_dboption N'tongxunlu', N'single', N'false'
GO

exec sp_dboption N'tongxunlu', N'autoshrink', N'true'
GO

exec sp_dboption N'tongxunlu', N'ANSI null default', N'false'
GO

exec sp_dboption N'tongxunlu', N'recursive triggers', N'false'
GO

exec sp_dboption N'tongxunlu', N'ANSI nulls', N'false'
GO

exec sp_dboption N'tongxunlu', N'concat null yields null', N'false'
GO

exec sp_dboption N'tongxunlu', N'cursor close on commit', N'false'
GO

exec sp_dboption N'tongxunlu', N'default to local cursor', N'false'
GO

exec sp_dboption N'tongxunlu', N'quoted identifier', N'false'
GO

exec sp_dboption N'tongxunlu', N'ANSI warnings', N'false'
GO

exec sp_dboption N'tongxunlu', N'auto create statistics', N'true'
GO

exec sp_dboption N'tongxunlu', N'auto update statistics', N'true'
GO

if( ( (@@microsoftversion / power(2, 24) = 8) and (@@microsoftversion & 0xffff >= 724) ) or ( (@@microsoftversion / power(2, 24) = 7) and (@@microsoftversion & 0xffff >= 1082) ) )
	exec sp_dboption N'tongxunlu', N'db chaining', N'false'
GO

use [tongxunlu]
GO

/****** Object:  Table [dbo].[Class]    Script Date: 2007-4-3 16:23:53 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Class]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Class]
GO

/****** Object:  Table [dbo].[MessageBook]    Script Date: 2007-4-3 16:23:53 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[MessageBook]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[MessageBook]
GO

/****** Object:  Table [dbo].[UserInfo]    Script Date: 2007-4-3 16:23:53 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[UserInfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[UserInfo]
GO

/****** Object:  Login budget    Script Date: 2007-4-3 16:23:52 ******/
if not exists (select * from master.dbo.syslogins where loginname = N'budget')
BEGIN
	declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'budget', @loginlang = N'简体中文'
	if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)
		select @logindb = N'master'
	if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')
		select @loginlang = @@language
	exec sp_addlogin N'budget', null, @logindb, @loginlang
END
GO

/****** Object:  Login gwy    Script Date: 2007-4-3 16:23:52 ******/
if not exists (select * from master.dbo.syslogins where loginname = N'gwy')
BEGIN
	declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'gwy', @loginlang = N'简体中文'
	if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)
		select @logindb = N'master'
	if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')
		select @loginlang = @@language
	exec sp_addlogin N'gwy', null, @logindb, @loginlang
END
GO

/****** Object:  Login tongxunlu    Script Date: 2007-4-3 16:23:52 ******/
if not exists (select * from master.dbo.syslogins where loginname = N'tongxunlu')
BEGIN
	declare @logindb nvarchar(132), @loginlang nvarchar(132) select @logindb = N'tongxunlu', @loginlang = N'简体中文'
	if @logindb is null or not exists (select * from master.dbo.sysdatabases where name = @logindb)
		select @logindb = N'master'
	if @loginlang is null or (not exists (select * from master.dbo.syslanguages where name = @loginlang) and @loginlang <> N'us_english')
		select @loginlang = @@language
	exec sp_addlogin N'tongxunlu', null, @logindb, @loginlang
END
GO

/****** Object:  User dbo    Script Date: 2007-4-3 16:23:52 ******/
/****** Object:  User tongxunlu    Script Date: 2007-4-3 16:23:52 ******/
if not exists (select * from dbo.sysusers where name = N'tongxunlu' and uid < 16382)
	EXEC sp_grantdbaccess N'tongxunlu', N'tongxunlu'
GO

/****** Object:  User tongxunlu    Script Date: 2007-4-3 16:23:52 ******/
exec sp_addrolemember N'db_owner', N'tongxunlu'
GO

/****** Object:  Table [dbo].[Class]    Script Date: 2007-4-3 16:23:54 ******/
CREATE TABLE [dbo].[Class] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[UserName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[ClassName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[MessageBook]    Script Date: 2007-4-3 16:23:56 ******/
CREATE TABLE [dbo].[MessageBook] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[UserName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[AddDate] [datetime] NULL ,
	[ClassId] [int] NOT NULL ,
	[Name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[Sex] [char] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[Birthday] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[Mobile] [varchar] (11) COLLATE Chinese_PRC_CI_AS NULL ,
	[P_Telephone] [varchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
	[QQ] [varchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
	[Email] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
	[HomePage] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
	[HomeAddress] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
	[HomePostCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[HomeTelephone] [varchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
	[WorkName] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
	[WorkDuty] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
	[WorkAddress] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
	[WorkPostCode] [varchar] (6) COLLATE Chinese_PRC_CI_AS NULL ,
	[WorkTelephone] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[WorkFax] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[Introduce] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL ,
	[Bz] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[UserInfo]    Script Date: 2007-4-3 16:23:56 ******/
CREATE TABLE [dbo].[UserInfo] (
	[id] [int] IDENTITY (1, 1) NOT NULL ,
	[UserName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
	[PassWord] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
	[Sex] [char] (2) COLLATE Chinese_PRC_CI_AS NULL ,
	[Email] [varchar] (150) COLLATE Chinese_PRC_CI_AS NULL ,
	[TrueName] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[RegDate] [datetime] NULL ,
	[UserLevel] [char] (1) COLLATE Chinese_PRC_CI_AS NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Class] WITH NOCHECK ADD 
	CONSTRAINT [PK_Class] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[MessageBook] WITH NOCHECK ADD 
	CONSTRAINT [PK_MessageBook] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[UserInfo] WITH NOCHECK ADD 
	CONSTRAINT [PK_User] PRIMARY KEY  CLUSTERED 
	(
		[id]
	)  ON [PRIMARY] 
GO

