操作表结构的语句

转载 2006年06月07日 21:36:00
看看这个论坛的数据库结构吧,比较经典:
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

SQL语句动态修改表结构(增加删除列)

ALTER   TABLE   TableName   add   ColumnName   VARCHAR(20)   NULL   ALTER   TABLE   TableName   DROP...
  • jiangfeng128
  • jiangfeng128
  • 2006-10-26 12:09:00
  • 2398

SQL 语句查看表结构

exec sp_help ‘表名’ ===================================== 怎样在sql sever中用sql命令查看表结构? 可以使用内置的...
  • u010586842
  • u010586842
  • 2014-10-24 13:43:11
  • 9834

常用数据表结构修改sql语句(oracle)

修改表名:ALTER TABLE srcRENAME  TO dest;修改列名:ALTER TABLE tablename RENAME COLUMN src TO dest;修改列的数据类型:AL...
  • netingcn
  • netingcn
  • 2006-07-17 11:39:00
  • 15541

使用SQL语句导出表结构

--老大写的SQLSELECT TableName=o.name,OWNER=USER_NAME(o.uid),TableDescription=ISNULL(ptb.value,N),FieldId...
  • swfcsunboy
  • swfcsunboy
  • 2007-09-09 19:36:00
  • 3894

oracle中用sql语句查看表的列名及结构

在PL/SQL中 select *  from user_tab_columns where table_name = 'LES_TEACHERSTORAGE' --其中LES_TEACHERST...
  • u014792342
  • u014792342
  • 2015-12-23 11:08:50
  • 4553

DB2查看表结构及所用表语句

DB2查看表结构及所用表语句   查看所用表(注:条件内容需要大写)    www.2cto.com   Sql代码   select * from sysibm.systables whe...
  • muzai
  • muzai
  • 2014-02-21 16:11:32
  • 11142

用SQL语句修改SQL表结构

最近,由于工作需要使用了SQL 2008数据库,遇到一些问题。当用户在在SQL Server 2008企业管理器中更改表结构时,必须要先删除原来的表,然后重新创建新表,才能完成表的更改,如果强行更改会...
  • yangna01314
  • yangna01314
  • 2010-03-12 19:27:00
  • 4768

oracle 中更改表的结构语句

1.编辑表的字段:   修改一个列的数据类型(一般限于修改长度,修改为一个不同类型时有诸多限制):  语法:    ALTER TABLE 表名 MODIFY(列名 数据类型); eg1:   alt...
  • gaogao0603
  • gaogao0603
  • 2008-11-20 11:25:00
  • 12613

SQL语句修改数据库表结构

一、查看表结构     1、查看表的基本结构语句:       DESCRIBE `DEPT`;     2、查看表详细结构语句:       SHOW CREATE TABLE `DEPT`; 二、...
  • bai_juaner
  • bai_juaner
  • 2013-03-13 19:54:37
  • 1760

修改表结构DDL语句与锁

--当pg开启一个事务,执行dml操作时,如果另一个事务要修改表结构,其不得不等待 --session1 中执行dml postgres=# begin; BEGIN postgres=# s...
  • jumewo
  • jumewo
  • 2015-10-22 11:55:25
  • 939
收藏助手
不良信息举报
您举报文章:操作表结构的语句
举报原因:
原因补充:

(最多只允许输入30个字)