建立数据库
建立數據庫
?
? ? ? ? ? ? 很簡單,都是重復的代碼,但是還有一些小的問題,具體說明如下
技巧以第一個表basicdata基本信息表為例,建立表的時候,參考已有的機房數據庫簡歷表,找到對應的表,表下的列,展開,你會發現有很清楚的說明,直接參照建立即可。
? ? ? ? ? 從中可以知道,basicdata表中的每個列的字段,包括字段名,數據類型,長度約束,是否允許為空,還有是否設置各種約束等。
?
?
?
create table [dbo].[basicdata_info]( [rate][numeric](19,4)not null, [tmprate][numeric](19,4)not null, [unittime][int]not null, [leasttime][int]not null, [preparetime][int]not null, [limitcash][numeric](19,4)not null, [head][char](10)not null, [date][date]not null, [time][time](0)not null )on [primary] go?
同理,具體的代碼如下:
?
?
use master goif exists(select*from dbo.sysdatabases where name='charge_sys') drop database student gocreate database charge_sys go use charge_sys goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[basicdata_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[basicdata_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[cancelcard_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[cancelcard_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[checkday_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[checkday_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[checkweek_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[checkweek_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[line_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[line_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[online_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[online_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[onwork_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[onwork_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[recharge_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[recharge_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[student_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[student_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[user_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[user_info] goif exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[worklog_info]')and objectproperty(id,N'isusertable')=1) drop table [dbo].[worklog_info] gocreate table [dbo].[basicdata_info]( [rate][numeric](19,4)not null, [tmprate][numeric](19,4)not null, [unittime][int]not null, [leasttime][int]not null, [preparetime][int]not null, [limitcash][numeric](19,4)not null, [head][char](10)not null, [date][date]not null, [time][time](0)not null )on [primary] gocreate table [dbo].[cancelcard_info]( [studentno][char](10)not null, [cardno][char](10)not null, [cancelcash][numeric](18,1)not null, [date][date]not null, [time][char](10)not null, [userid][char](10)not null, [status][char](10)not null )on [primary] gocreate table [dbo].[checkday_info]( [remaincash][numeric](18,0)not null, [rechargecash][numeric](18,0)not null, [consumecash][numeric](18,0)not null, [cancelcash][numeric](18,0)not null, [allcash][numeric](18,0)not null, [date][date]not null )on [primary] gocreate table [dbo].[checkweek_info]( [remaincash][numeric](18,0)not null, [rechargecash][numeric](18,0)not null, [consumecash][numeric](18,0)not null, [cancelcash][numeric](18,0)not null, [allcash][numeric](18,0)not null, [date][date]not null )on [primary] gocreate table [dbo].[line_info]( [serial][numeric](18,0)not null, [cardno][char](10)not null, [studentno][char](11)not null, [studentname][char](10)not null, [department][char](10)not null, [sex][char](10)not null, [ondate][date]not null, [ontime][time](0)not null, [offdate][date]not null, [offtime][time](0)not null, [consumetiem][char](10)not null, [consume][numeric](18,1)not null, [cash][numeric](18,1)not null, [status][char](8)not null, [computer][char](10)not null )on [primary] gocreate table [dbo].[online_info]( [cardno][char](10)not null, [cardtype][char](10)not null, [studentno][char](11)not null, [studentname][char](10)not null, [department][char](10)not null, [sex][char](10)not null, [ondate][date]not null, [ontime][time](0)not null, [computer][char](10)not null, [date][datetime2](0)not null )on [primary] gocreate table [dbo].[onwork_info]( [userid][char](10)not null, [level][char](10)not null, [logindate][date]null, [logintime][time](0)null, [computer][char](10)null )on [primary] gocreate table [dbo].[recharge_info]( [serial][numeric](18,0)not null, [studentno][char](11)null, [cardno][char](10)not null, [addmoney][numeric](19,4)not null, [date][date]null, [time][time](0)null, [userid][char](10)null, [status][char](10)null )on [primary] gocreate table [dbo].[student_info]( [cardno][char](10)not null, [studentno][char](11)null, [studentname][char](10)null, [sex][char](6)null, [department][char](10)null, [grade][char](10)null, [class][char](10)null, [cash][numeric](10,3)not null, [explain][varchar](50)null, [userid][char](10)not null, [status][char](10)not null, [ischeck][char](10)not null, [date][date]not null, [time][time](0)not null, [type][char](10)null )on [primary] gocreate table [dbo].[user_info]( [userid][int]not null, [pwd][char](10)null, [level][char](8)null, [username][char](10)null, [head][char](10)null primary key(userid) )on [primary] gocreate table [dbo].[worklog_info]( [serial][numeric](18,0)not null, [userid][char](10)null, [level][char](10)null, [logindate][date]null, [logintime][time](0)null, [logoutdate][date]null, [logouttime][time](0)null, [computer][char](10)null, [status][char](10)not null )on [primary] go
? ? ? ? ?這樣,建立好數據庫之后,分析,執行,建立數據庫沒有任何問題,但是使用的時候回有問題,因為所有的表都是空的,無法登陸使用,除非把主窗體設置為第一個啟動窗體。
?
insert user_info(userid,pwd ) values('1','1')? ? ? ? ?這段代碼,是指定一個用于登陸的用戶和密碼,學生中也有,否則只能從主窗體啟動。
?
?
?
? ? ? ? ? ?使用自己建立的數據庫是無法登陸到給的機房系統的,一旦登陸就會報錯,就是這個錯誤,而且不是計算機用戶名的問題,具體參照博客:點擊打開鏈接
?
?
?
? ? ? ? ? ? 新建的數據庫只能自己敲的系統使用,給的系統不能使用,初步懷疑,是數據表,其中的字段命名有問題,包括其中的大小寫,自建數據庫中表和字段名全部都使用的小寫,而給的機房打開其中的數據表和字段有的字母都是大寫。
? ? ? ? ? ? 機房給的數據庫中的表和字段的命名有的不規范,精英都是非常優秀的,要成為精英必須要注意這些小的細節,比如命名,從現在就應該掌握正確的命名規范,以后要做的系統還有很多,目前打算把所用的名字都改為給的機房的數據庫的表名和字段名,模擬機房數據庫,把所有的名稱都改成機房的原有的的數據庫名稱。
?
? ? ? ? ? ? 自建數據庫使用一個別名,在自己做的機房收費系統中使用,把給的機房系統和建立的模擬機房數據庫連接上,這樣就可以參考給的機房,做自己的機房,其實,也不用自己建立模擬的機房數據庫,直接連接給的機房數據庫,給的機房就可以運行,然后自己做的機房,給自建的數據庫起個別名就行了。
?
? ? ? ? ? ? 不光要給數據庫起個別名,還必須把里面所有的表都要起個別名,這樣有點就麻煩了,因為,在建立兩個數據庫時,數據庫的名稱不可以一樣,而且,里面所有的表的表名都不可以一樣,如果某個表名一樣的話,后建立的一個數據庫就會把先建立的數據庫中的這個表,即表名相同的表給刪除掉。
?
總結