如何在第一次运行时在程序里面生成sql7的表?(30分)

  • 主题发起人 主题发起人 狼牙
  • 开始时间 开始时间

狼牙

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在第一次运行时在程序里面生成sql7的表?
在sql7里面生成一个database,再生成多个表,请问是如何实现的?

 
create database
create table
 
同意楼上的!
 
IF NOT EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'Music')
begin
declare @dbpath nvarchar(200)
declare @sql nvarchar(1000)
exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE','SOFTWARE/Microsoft/MSSQLSERVER/setup','SQLDataRoot',@dbpath output
set @sql='CREATE DATABASE [Music] ON (NAME = Music, FILENAME =''' + @dbpath + '/data/Music.MDF'' , SIZE = 3, FILEGROWTH = 10%) LOG ON (NAME = Music_log, FILENAME =''' + @dbpath + '/data/Music_log.LDF'' , SIZE = 1, FILEGROWTH = 10%)'
exec(@sql)
end
GO

use music
GO

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

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

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

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

CREATE TABLE [dbo].[JS_Course] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[CourseName] [varchar] (50) NOT NULL ,
[Price] [int] NULL ,
[Disable] [tinyint] NOT NULL ,
[Decp] [nvarchar] (500) NULL ,
[FilePath] [nvarchar] (50) NULL ,
[CourseLeix] [smallint] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[JS_LOG] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[cIp] [nvarchar] (15) NOT NULL ,
[Riqsj] [nvarchar] (19) NULL ,
[cDns] [nvarchar] (255) NULL ,
[cStreamn] [nvarchar] (255) NULL ,
[cStime] [int] NULL ,
[xDurtime] [numeric](10, 0) NULL ,
[cRate] [int] NULL ,
[cStatus] [int] NULL ,
[cPlayerID] [nvarchar] (100) NULL ,
[cPlayerVer] [nvarchar] (100) NULL ,
[cPlayerLang] [nvarchar] (100) NULL ,
[csUserAgent] [nvarchar] (255) NULL ,
[csReferer] [nvarchar] (255) NULL ,
[cHostexe] [nvarchar] (100) NULL ,
[cHostexeVer] [nvarchar] (100) NULL ,
[cOs] [nvarchar] (100) NULL ,
[cOsVer] [nvarchar] (100) NULL ,
[cCpu] [nvarchar] (100) NULL ,
[FileLen] [numeric](10, 0) NULL ,
[FileSize] [numeric](10, 0) NULL ,
[AvgBandWidth] [numeric](10, 0) NULL ,
[Protocol] [nvarchar] (100) NULL ,
[Transport] [nvarchar] (100) NULL ,
[AudioCodec] [nvarchar] (100) NULL ,
[VideoCodec] [nvarchar] (100) NULL ,
[ChannelURL] [nvarchar] (255) NULL ,
[scBytes] [numeric](10, 0) NULL ,
[cBytes] [numeric](10, 0) NULL ,
[spSent] [numeric](10, 0) NULL ,
[cpReceived] [numeric](10, 0) NULL ,
[cpLostc] [numeric](10, 0) NULL ,
[cpLostn] [numeric](10, 0) NULL ,
[cpLostcn] [numeric](10, 0) NULL ,
[cRReqs] [int] NULL ,
[cpRECC] [numeric](10, 0) NULL ,
[cpRResent] [numeric](10, 0) NULL ,
[cBufferTime] [numeric](10, 0) NULL ,
[ctBufferTime] [numeric](10, 0) NULL ,
[cQuality] [int] NULL ,
[sIp] [nvarchar] (15) NULL ,
[sDns] [nvarchar] (255) NULL ,
[stClients] [int] NULL ,
[sCpuUtil] [int] NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[JS_Online] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [nvarchar] (30) NOT NULL ,
[UserIP] [nvarchar] (15) NOT NULL ,
[LogInTime] [nvarchar] (19) NULL ,
[LogOutTime] [nvarchar] (19) NULL ,
[DurTime] [numeric](10, 0) NULL
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[JS_User] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[UserName] [nvarchar] (30) NOT NULL ,
[Password] [nvarchar] (30) NULL ,
[TotalTime] [numeric](10, 0) NULL ,
[Status] [smallint] NULL ,
[CourseId] [smallint] NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[JS_Course] WITH NOCHECK ADD
CONSTRAINT [PK_JS_Course] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[JS_LOG] WITH NOCHECK ADD
CONSTRAINT [ID_JS_LOG] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[JS_Online] WITH NOCHECK ADD
CONSTRAINT [PK_JS_Name2IP] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[JS_User] WITH NOCHECK ADD
CONSTRAINT [PK_JS_User] PRIMARY KEY CLUSTERED
(
[ID]
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[JS_Course] WITH NOCHECK ADD
CONSTRAINT [DF_JS_Course_Disable] DEFAULT (0) FOR [Disable],
CONSTRAINT [DF_JS_Course_CourseLeix] DEFAULT (0) FOR [CourseLeix]
GO

ALTER TABLE [dbo].[JS_LOG] WITH NOCHECK ADD
CONSTRAINT [DF_JS_LOG_cStime] DEFAULT (0) FOR [cStime],
CONSTRAINT [DF_JS_LOG_xDurtime] DEFAULT (0) FOR [xDurtime],
CONSTRAINT [DF_JS_LOG_cRate] DEFAULT (0) FOR [cRate],
CONSTRAINT [DF_JS_LOG_cStatus] DEFAULT (0) FOR [cStatus],
CONSTRAINT [DF_JS_LOG_FileLen] DEFAULT (0) FOR [FileLen],
CONSTRAINT [DF_JS_LOG_FileSize] DEFAULT (0) FOR [FileSize],
CONSTRAINT [DF_JS_LOG_AvgBandWidth] DEFAULT (0) FOR [AvgBandWidth],
CONSTRAINT [DF_JS_LOG_scBytes] DEFAULT (0) FOR [scBytes],
CONSTRAINT [DF_JS_LOG_cBytes] DEFAULT (0) FOR [cBytes],
CONSTRAINT [DF_JS_LOG_spSent] DEFAULT (0) FOR [spSent],
CONSTRAINT [DF_JS_LOG_cpReceived] DEFAULT (0) FOR [cpReceived],
CONSTRAINT [DF_JS_LOG_cpLostc] DEFAULT (0) FOR [cpLostc],
CONSTRAINT [DF_JS_LOG_cpLostn] DEFAULT (0) FOR [cpLostn],
CONSTRAINT [DF_JS_LOG_cpLostcn] DEFAULT (0) FOR [cpLostcn],
CONSTRAINT [DF_JS_LOG_cRReqs] DEFAULT (0) FOR [cRReqs],
CONSTRAINT [DF_JS_LOG_cpRECC] DEFAULT (0) FOR [cpRECC],
CONSTRAINT [DF_JS_LOG_cpRResent] DEFAULT (0) FOR [cpRResent],
CONSTRAINT [DF_JS_LOG_cBufferTime] DEFAULT (0) FOR [cBufferTime],
CONSTRAINT [DF_JS_LOG_ctBufferTime] DEFAULT (0) FOR [ctBufferTime],
CONSTRAINT [DF_JS_LOG_cQuality] DEFAULT (0) FOR [cQuality],
CONSTRAINT [DF_JS_LOG_stClients] DEFAULT (0) FOR [stClients],
CONSTRAINT [DF_JS_LOG_sCpuUtil] DEFAULT (0) FOR [sCpuUtil]
GO

ALTER TABLE [dbo].[JS_Online] WITH NOCHECK ADD
CONSTRAINT [DF_JS_Online_DurTime] DEFAULT (0) FOR [DurTime]
GO

ALTER TABLE [dbo].[JS_User] WITH NOCHECK ADD
CONSTRAINT [DF_JS_User_TotalTime] DEFAULT (72000) FOR [TotalTime],
CONSTRAINT [DF_JS_User_Status] DEFAULT (0) FOR [Status]
GO

 
这个是我以前写的一个sql语句!自己改改吧!该有的功能都有了!
[red]注意是SqlServer2000的数据库!和7不太一样![/red]
 
注意是SqlServer2000的数据库!和7不太一样!
昏!
谁有简单的例子吗???给我个Source吧。简单至之需要两个按钮,一个生成一个名为
tj的database
一个生成一个名为tj_exter的表......
如能带注释就更好了。。。
wolfteeth@21cn.com谢。。。
 
从手工做好的数据库中导出脚本,保存为wintext file,在程序中load。
 
多人接受答案了。
 
后退
顶部