【SQL开源代码栏目提醒】:网学会员在SQL开源代码频道为大家收集整理了RelationCustomerTrace.sql提供大家参考,希望对大家有所帮助!
/*==============================================================*/
/* Database name: RelationCustomerTrace */
/* DBMS name: Microsoft SQL Server 2000 */
/* Created on: 2005-11-19 4:07:10 */
/*==============================================================*/
alter table customer
drop constraint FK_CUSTOMER_RELATIONS_CUSTOMER
go
alter table relation
drop constraint FK_RELATION_RELATIONS_CUSTOMER
go
alter table trace
drop constraint FK_TRACE_RELATIONS_CUSTOMER
go
alter table trace
drop constraint FK_TRACE_RELATIONS_RELATION
go
if exists (select 1
from sysindexes
where id = object_id('customer')
and name = 'Relationship_1_FK'
and indid > 0
and indid < 255)
drop index customer.Relationship_1_FK
go
if exists (select 1
from sysindexes
where id = object_id('relation')
and name = 'Relationship_2_FK'
and indid > 0
and indid < 255)
drop index relation.Relationship_2_FK
go
if exists (select 1
from sysindexes
where id = object_id('trace')
and name = 'Relationship_3_FK'
and indid > 0
and indid < 255)
drop index trace.Relationship_3_FK
go
if exists (select 1
from sysindexes
where id = object_id('trace')
and name = 'Relationship_4_FK'
and indid > 0
and indid < 255)
drop index trace.Relationship_4_FK
go
if exists (select 1
from sysobjects
where id = object_id('customer')
and type = 'U')
drop table customer
go
if exists (select 1
from sysobjects
where id = object_id('customerType')
and type = 'U')
drop table customerType
go
if exists (select 1
from sysobjects
where id = object_id('relation')
and type = 'U')
drop table relation
go
if exists (select 1
from sysobjects
where id = object_id('trace')
and type = 'U')
drop table trace
go
/*==============================================================*/
/* Table: customer */
/*==============================================================*/
create table customer (
customercode varchar(32) not null,
customertypecode varchar(32) null,
customername varchar(50) null,
address varchar(100) null,
phone varchar(20) null,
mobile varchar(12) null,
email varchar(100) null,
birthday datetime null,
hobby varchar(30) null,
note varchar(255) null,
constraint PK_CUSTOMER primary key (customercode)
)
go
/*==============================================================*/
/* Index: Relationship_1_FK */
/*==============================================================*/
create index Relationship_1_FK on customer (
customertypecode
)
go
/*==============================================================*/
/* Table: customerType */
/*==============================================================*/
create table customerType (
customertypecode varchar(32) not null,
customertypename varchar(50) null,
constraint PK_CUSTOMERTYPE primary key (customertypecode)
)
go
/*==============================================================*/
/* Table: relation */
/*==============================================================*/
create table relation (
relationcode varchar(32) not null,
customercode varchar(32) null,
relationname varchar(20) null,
constraint PK_RELATION primary key (relationcode)
)
go
/*==============================================================*/
/* Index: Relationship_2_FK */
/*==============================================================*/
create index Relationship_2_FK on relation (
customercode
)
go
/*==============================================================*/
/* Table: trace */
/*==============================================================*/
create table trace (
tracecode varchar(32) not null,
relationcode varchar(32) null,
customercode varchar(32) null,
tracedate datetime null,
tracecontent varchar(255) null,
note varchar(255) null,
constraint PK_TRACE primary key (tracecode)
)
go
/*==============================================================*/
/* Index: Relationship_3_FK */
/*==============================================================*/
create index Relationship_3_FK on trace (
customercode
)
go
/*==============================================================*/
/* Index: Relationship_4_FK */
/*==============================================================*/
create index Relationship_4_FK on trace (
relationcode
)
go
alter table customer
add constraint FK_CUSTOMER_RELATIONS_CUSTOMER foreign key (custome