标题:同时用SQL语言建立数个数据库
只看楼主
junzheyang
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-4-14
 问题点数:0 回复次数:2 
同时用SQL语言建立数个数据库
有大虾知道怎么样用sql语句同时建立几个数据库吗?比如T1,T2,T3。最好能发一个实例给我。万分感谢
搜索更多相关主题的帖子: SQL 数据库 语言 
2007-04-14 15:05
从小到大
Rank: 1
等 级:新手上路
威 望:2
帖 子:200
专家分:0
注 册:2006-6-24
得分:0 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__discounts__stor___0F975522]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[discounts] DROP CONSTRAINT FK__discounts__stor___0F975522
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__sales__stor_id__0AD2A005]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[sales] DROP CONSTRAINT FK__sales__stor_id__0AD2A005
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__roysched__title___0DAF0CB0]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[roysched] DROP CONSTRAINT FK__roysched__title___0DAF0CB0
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__sales__title_id__0BC6C43E]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[sales] DROP CONSTRAINT FK__sales__title_id__0BC6C43E
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__titleauth__title__060DEAE8]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[titleauthor] DROP CONSTRAINT FK__titleauth__title__060DEAE8
GO

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

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

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

CREATE TABLE [dbo].[stores] (
[stor_id] [char] (4) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[stor_name] [varchar] (40) COLLATE Chinese_PRC_CI_AS NULL ,
[stor_address] [varchar] (40) COLLATE Chinese_PRC_CI_AS NULL ,
[city] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ,
[state] [char] (2) COLLATE Chinese_PRC_CI_AS NULL ,
[zip] [char] (5) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[titleauthor] (
[au_id] [id] NOT NULL ,
[title_id] [tid] NOT NULL ,
[au_ord] [tinyint] NULL ,
[royaltyper] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[titles] (
[title_id] [tid] NOT NULL ,
[title] [varchar] (80) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[type] [char] (12) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[pub_id] [char] (4) COLLATE Chinese_PRC_CI_AS NULL ,
[price] [money] NULL ,
[advance] [money] NULL ,
[royalty] [int] NULL ,
[ytd_sales] [int] NULL ,
[notes] [varchar] (200) COLLATE Chinese_PRC_CI_AS NULL ,
[pubdate] [datetime] NOT NULL
) ON [PRIMARY]
GO


2007-04-14 23:12
帅哥一条虫
Rank: 1
等 级:新手上路
威 望:1
帖 子:65
专家分:0
注 册:2006-10-15
得分:0 

楼上的是建多个表的吧!

2007-04-14 23:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-131819-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.043698 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved