关闭

操作表结构的语句

946人阅读 评论(0) 收藏 举报
看看这个论坛的数据库结构吧,比较经典:
if exists (select * from sysobjects where id = object_id(N'[dbo].
[Announce]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Announce]
GO

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

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

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

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

CREATE TABLE [dbo].[Announce] (
[AnnounceID] [int] IDENTITY (1, 1) NOT NULL ,
[ParentID] [int] NULL ,
[Child] [int] NULL ,
[BoardID] [int] NULL ,
[UserName] [nvarchar] (50) NULL ,
[UserEmail] [nvarchar] (255) NULL ,
[URL] [nvarchar] (255) NULL ,
[URLTitle] [nvarchar] (255) NULL ,
[URLPic] [nvarchar] (255) NULL ,
[Topic] [nvarchar] (255) NULL ,
[Body] [ntext] NULL ,
[DateAndTime] [nvarchar] (50) NULL ,
[hits] [int] NULL ,
[length] [int] NULL ,
[RootID] [int] NULL ,
[layer] [int] NULL ,
[orders] [int] NULL ,
[emote] [int] NULL ,
[ip] [nvarchar] (20) NULL ,
[signature] [nvarchar] (255) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[board] (
[BoardID] [int] IDENTITY (1, 1) NOT NULL ,
[BoardName] [nvarchar] (100) NULL ,
[BoardMaster] [int] NULL ,
[ignoreip] [nvarchar] (255) NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[essence] (
[id] [int] IDENTITY (1, 1) NOT NULL ,
[announceid] [int] NULL ,
[boardid] [int] NULL ,
[username] [nvarchar] (50) NULL ,
[useremail] [nvarchar] (255) NULL ,
[url] [nvarchar] (255) NULL ,
[urlTitle] [nvarchar] (255) NULL ,
[urlPic] [nvarchar] (255) NULL ,
[Topic] [nvarchar] (255) NULL ,
[Body] [ntext] NULL ,
[dateAndTime] [nvarchar] (50) NULL ,
[hits] [int] NULL ,
[length] [int] NULL ,
[emote] [int] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

CREATE TABLE [dbo].[site] (
[SiteMasterPwd] [nvarchar] (50) NULL
) ON [PRIMARY]
GO

INSERT INTO [site]([SiteMasterPwd]) VALUES("intels")
GO

CREATE TABLE [dbo].[user] (
[UserID] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [nvarchar] (50) NULL ,
[UserEmail] [nvarchar] (255) NULL ,
[UserPassword] [nvarchar] (11) NULL ,
[icq] [nvarchar] (20) NULL ,
[homepage] [nvarchar] (255) NULL ,
[sex] [nvarchar] (10) NULL ,
[passanswer] [nvarchar] (100) NULL ,
[lastvisit] [smalldatetime] NULL ,
[incometime] [smalldatetime] NULL ,
[birthday] [smalldatetime] NULL ,
[points] [int] NULL ,
[visits] [int] NULL ,
[country] [nvarchar] (20) NULL ,
[city] [nvarchar] (20) NULL ,
[passquest] [nvarchar] (100) NULL ,
[signature] [nvarchar] (255) NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Announce] WITH NOCHECK ADD
CONSTRAINT [PK_Announce] PRIMARY KEY NONCLUSTERED
(
[AnnounceID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[board] WITH NOCHECK ADD
CONSTRAINT [PK_board] PRIMARY KEY NONCLUSTERED
(
[BoardID]
) ON [PRIMARY]
GO


ALTER TABLE [dbo].[essence] WITH NOCHECK ADD
CONSTRAINT [PK_essence] PRIMARY KEY NONCLUSTERED
(
[id]
) ON [PRIMARY]
GO


ALTER TABLE [dbo].[user] WITH NOCHECK ADD
CONSTRAINT [PK_user] PRIMARY KEY NONCLUSTERED
(
[UserID]
) ON [PRIMARY]
GO

CREATE INDEX [announce_i] ON [dbo].[Announce]([RootID], [ParentID])
ON [PRIMARY]
GO

CREATE INDEX [Boardid] ON [dbo].[Announce]([BoardID]) ON [PRIMARY]
GO

CREATE INDEX [Boardid] ON [dbo].[essence]([boardid]) ON [PRIMARY]
GO

CREATE INDEX [points] ON [dbo].[user]([points]) ON [PRIMARY]
GO

CREATE INDEX [username] ON [dbo].[user]([UserName]) ON [PRIMARY]
GO
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:260599次
    • 积分:2971
    • 等级:
    • 排名:第11843名
    • 原创:62篇
    • 转载:53篇
    • 译文:0篇
    • 评论:50条
    最新评论