駕照理論考試速成,模訪一個軟件做成的
數(shù)據(jù)庫是mssql2005,在JzData.rar文件中,附加即可;
如果你使用的是sql 2000的數(shù)據(jù)庫,請將debug目錄下的access數(shù)據(jù)庫jzdata.mdb轉(zhuǎn)換成sql server數(shù)據(jù)庫,在查詢分析器里執(zhí)行:
exec sp_configure 'show advanced options',1 reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1 reconfigure
create database jz
go
use jz
SELECT *
INTO car
FROM OPENDATASOURCE ('Microsoft.Jet.OLEDB.4.0',
'Data Source="D:\GCLsoft\jz\Debug\jzdata.mdb";User ID=Admin;Password=' )...car
SELECT *
INTO moto
FROM OPENDATASOURCE ('Microsoft.Jet.OLEDB.4.0',
'Data Source="D:\GCLsoft\jz\Debug\jzdata.mdb";User ID=Admin;Password=' )...moto
use jz
alter table car alter column id int not null
go
alter table car add constraint pkKey1 primary key (id)
alter table moto alter column id int not null
go
alter table moto add constraint pkKey2 primary key (id) --設(shè)置主鍵
數(shù)據(jù)庫名字:jz
代碼是C++寫的,用vc6打開
代碼寫的不好,如果你有什么好的建議,歡迎與我聯(lián)系
源代碼下載地址

在sql2000下,點考試會出現(xiàn)錯誤:如果語句中包含 UNION 運算符,那么 ORDER BY 子句中的項就必須出現(xiàn)在選擇列表中。解決方法,改用視圖,在代碼里要修改一下:
if exists
(select * from dbo.sysobjects where id = object_id(N'[dbo].[v1]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view v1
go
create view v1 as
select top 30 * from car where zhanjie=1 ORDER BY NEWID()
go
if exists
(select * from dbo.sysobjects where id = object_id(N'[dbo].[v2]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view v2
go
create view v2 as
select top 20 * from car where zhanjie=2 ORDER BY NEWID()
go
select * from v1
union all
select * from v2
如果不想使用視圖,sql語句這樣寫,也可以解決問題:
select * from
(
select * from
(
select top 30 * from car where zhanjie=1 ORDER BY NEWID()
) as a1
union all
select * from
(
select top 20 * from car where zhanjie=2 ORDER BY NEWID()
) as a2
) as a3
posted on 2010-01-29 13:22
fly931 閱讀(1378)
評論(0) 編輯 收藏 引用