建立数据库

建立数据库

 

            很简单,都是重复的代码,但是还有一些小的问题,具体说明如下
技巧以第一个表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 
go

if exists(select*from dbo.sysdatabases where name='charge_sys')
drop database student
go

create database charge_sys
go
use charge_sys 
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[basicdata_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[basicdata_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[cancelcard_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[cancelcard_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[checkday_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[checkday_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[checkweek_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[checkweek_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[line_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[line_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[online_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[online_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[onwork_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[onwork_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[recharge_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[recharge_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[student_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[student_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[user_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[user_info]
go

if exists(select*from dbo.sysobjects where id=object_id(N'[dbo].[worklog_info]')and objectproperty(id,N'isusertable')=1)
drop table [dbo].[worklog_info]
go

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

create 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]
go

create 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]
go

create 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]
go

create 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]
go

create 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]
go

create 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]
go

create 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]
go

create 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]
go

create 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]
go

create 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')

         这段代码,是指定一个用于登陆的用户和密码,学生中也有,否则只能从主窗体启动。

 

 

 

           使用自己建立的数据库是无法登陆到给的机房系统的,一旦登陆就会报错,就是这个错误,而且不是计算机用户名的问题,具体参照博客:点击打开链接

 

 

 


            新建的数据库只能自己敲的系统使用,给的系统不能使用,初步怀疑,是数据表,其中的字段命名有问题,包括其中的大小写,自建数据库中表和字段名全部都使用的小写,而给的机房打开其中的数据表和字段有的字母都是大写。
            机房给的数据库中的表和字段的命名有的不规范,精英都是非常优秀的,要成为精英必须要注意这些小的细节,比如命名,从现在就应该掌握正确的命名规范,以后要做的系统还有很多,目前打算把所用的名字都改为给的机房的数据库的表名和字段名,模拟机房数据库,把所有的名称都改成机房的原有的的数据库名称。

 

            自建数据库使用一个别名,在自己做的机房收费系统中使用,把给的机房系统和建立的模拟机房数据库连接上,这样就可以参考给的机房,做自己的机房,其实,也不用自己建立模拟的机房数据库,直接连接给的机房数据库,给的机房就可以运行,然后自己做的机房,给自建的数据库起个别名就行了。

 

            不光要给数据库起个别名,还必须把里面所有的表都要起个别名,这样有点就麻烦了,因为,在建立两个数据库时,数据库的名称不可以一样,而且,里面所有的表的表名都不可以一样,如果某个表名一样的话,后建立的一个数据库就会把先建立的数据库中的这个表,即表名相同的表给删除掉。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值