vb建立sql数据库
Dim objGz As RecordsetDim objCn As Connection
Dim strPath As String
Dim strName As String
Dim strNameMdf As String
Dim strNameLog As String
Dim pathNameMdf As String
Dim pathNameLog As String
Private Declare Function GetTickCount Lib "kernel32" () As Long
'创建数据库及表例子
Private Sub MakeNewMdf()
Set objCn = New Connection
strPath = App.Path
strName = "xxz" & Format(Date, "yyyymmdd")
strNameLog = strName & "_log"
strNameMdf = strName & "_data"
pathNameMdf = strPath & "\" & strNameMdf & ".mdf"
pathNameLog = strPath & "\" & strNameLog & ".ldf"
With objCn
.Provider = "SQLOLEDB"
.ConnectionString = "User Id =sa;pwd=editcopy;data source=CHINA-0563340EC;initial Catalog=master"
'.ConnectionString = "User Id =sa;" & strPwd & ";data source=(local);initial Catalog=信息站"
.Open
End With
'objCn.Execute "create database aa on primary(name =aa_data,filename=" & Chr(34) & "d:\aa_data.mdf" & Chr(34) & ",size=10mb,maxsize=20mb,filegrowth=2)log on(name =aa_log,filename=" & Chr(34) & "d:\aa_log.ldf" & Chr(34) & ",size=10mb,maxsize=20mb,filegrowth=2)"
'创建数据库
objCn.Execute "create database 信息站 on primary(name =" & strNameMdf & ",filename=" & Chr(34) & "" & pathNameMdf & ".mdf" & Chr(34) & ",size=10mb,maxsize=20mb,filegrowth=2)log on(name =" & strNameLog & ",filename=" & Chr(34) & "" & pathNameLog & ".ldf" & Chr(34) & ",size=10mb,maxsize=20mb,filegrowth=2)"
'打开刚刚创建的数据库
objCn.DefaultDatabase = "信息站"
objCn.Execute "CREATE TABLE [dbo].[三违处罚] (" & _
"[id] [int] IDENTITY (1, 1) NOT NULL ," & _
"[执罚人编号] [int] NOT NULL ," & _
"[三违人姓名] [char] (8) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[单位] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[工种] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[地点] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[罚款日期] [datetime] NOT NULL ," & _
"[性质] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[罚金] [int] NOT NULL ," & _
"[原因] [varchar] (500) COLLATE Chinese_PRC_CI_AS NOT NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[临时表] (" & _
"[姓名] [char] (8) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[单位] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[职务] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[入井日期] [datetime] NULL ," & _
"[入井时间] [datetime] NULL ," & _
"[升井日期] [datetime] NULL ," & _
"[升井时间] [datetime] NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[临时表记录] (" & _
"[inouttime] [datetime] NOT NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[人员信息] (" & _
"[id] [int] IDENTITY (1, 1) NOT NULL ," & _
"[姓名] [char] (8) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[性别] [char] (2) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[年龄] [tinyint] NULL ," & _
"[单位] [varchar] (20) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[职务] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[入井天数] [int] NULL ," & _
"[甲班] [int] NULL ," & _
"[乙班] [int] NULL ," & _
"[丙班] [int] NULL ," & _
"[罚款人次] [int] NULL ," & _
"[罚款金额] [int] NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[升井超时人员] (" & _
"[姓名] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[单位] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[职务] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[入井时间] [datetime] NULL ," & _
"[升井时间] [datetime] NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[升入井] (" & _
"[id] [int] IDENTITY (1, 1) NOT NULL ," & _
"[人员编号] [int] NOT NULL ," & _
"[入井时间] [datetime] NOT NULL ," & _
"[升井时间] [datetime] NOT NULL ," & _
"[入井日期] [datetime] NOT NULL ," & _
"[升井日期] [datetime] NOT NULL ," & _
"[安全信息卡] [int] NOT NULL ," & _
"[班种] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[入井时长] [nchar] (10) COLLATE Chinese_PRC_CI_AS NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[单位] (" & _
"[单位名称] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[安全信息卡] (" & _
"[id] [int] IDENTITY (1, 1) NOT NULL ," & _
"[人员编号] [int] NOT NULL ," & _
"[入井编号] [int] NOT NULL ," & _
"[入井地点] [char] (4) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[所经路线] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[隐患类别] [char] (8) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[隐患等级] [char] (8) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[责任人1] [char] (8) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[责任人2] [char] (8) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[隐患内容] [varchar] (3000) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[整改时间] [datetime] NOT NULL ," & _
"[完成情况] [char] (6) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[隐患地点] [varchar] (100) COLLATE Chinese_PRC_CI_AS NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[安全统计] (" & _
"[日期] [datetime] NULL ," & _
"[隐患条数] [int] NULL ," & _
"[易做图] [int] NULL ," & _
"[B级] [int] NULL ," & _
"[C级] [int] NULL ," & _
"[现场整改] [int] NULL ," & _
"[限期整改] [int] NULL ," & _
"[三违人数] [int] NULL ," & _
"[罚款金额] [int] NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[工种] (" & _
"[工种] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[用户] (" & _
"[姓名] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[口令] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[类型] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[质量处罚] (" & _
"[id] [int] IDENTITY (1, 1) NOT NULL ," & _
"[执罚人编号] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[责任人] [char] (8) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[单位] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[职务] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[处罚时间] [datetime] NOT NULL ," & _
"[地点] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[原因] [char] (10) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[罚金] [int] NOT NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[隐患排查] (" & _
"[名称] [char] (8) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[主查单位] [char] (30) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[易做图] [int] NULL ," & _
"[B级] [int] NULL ," & _
"[C级] [int] NULL ," & _
"[现场整改] [int] NULL ," & _
"[限期整改] [int] NULL ," & _
"[合计] [int] NULL ," & _
"[备注] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[领导] (" & _
"[id] [int] NULL ," & _
"[姓名] [char] (8) COLLATE Chinese_PRC_CI_AS NOT NULL " & _
") ON [PRIMARY]"
objCn.Execute "CREATE TABLE [dbo].[领导考核] (" & _
"[姓名] [char] (8) COLLATE Chinese_PRC_CI_AS NOT NULL ," & _
"[入井日期] [datetime] NULL ," & _
"[入井时间] [datetime] NULL ," & _
"[升井日期] [datetime] NULL ," & _
"[升井时间] [datetime] NULL ," & _
"[班种] [char] (10) COLLATE Chinese_PRC_CI_AS NULL ," & _
"[查处三违人次] [int] NULL ," & _
"[罚款金额] [int] NULL ," & _
"[查处隐患] [int] NULL ," & _
"[备注] [char] (10) COLLATE Chinese_PRC_CI_AS NULL " & _
") ON [PRIMARY]"
......
objCn.Close
Set objCn = Nothing
End Sub
Private Sub Pause(ByVal sSec As Long)
Dim StartSec As Long
StartSec = GetTickCount()
While (GetTickCount() - StartSec) / 1000 < sSec
DoEvents
Wend
End Sub
Private Sub Form_Load()
wait.Show
Pause (1)
MakeNewMdf
Unload Me
End Sub
--------------------编程问答-------------------- 要是我的话,我会SHELL外部的批处理+SQL文件,这样你不至于为了一个字段而修改VB源代码,LZ觉得呢 --------------------编程问答-------------------- 楼上的朋友,可以给个例子吗?我很想知道你说的方法,谢谢!!! --------------------编程问答-------------------- LZ能说一下代码在什么样的情况下怎样建立的啊?能给一下具体的么?
如:界面、属性等!谢谢!!!
补充:VB , 数据库(包含打印,安装,报表)