熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Delphi編程 >> 正文

經典案例 財務管理系統(5)

2013-11-23 17:35:43  來源: Delphi編程 
    ——此文章摘自《Delphi 數據庫開發經典案例解析》定價 特價 購買>>

  根據實例介紹科目表是系統的關鍵表其他各表均與科目表通過科目代碼字段進行多對一的關聯系統共需要張表用途分別如表所示

   創建數據庫

  打開SQL Server企業管理器新建一個數據庫名稱為caiwubook利用配書光盤中的腳本代碼\Chap\建庫腳本\ 財務管理系統實例程序sql文件創建數據庫對象完成數據庫的設計也可以利用\Chap\建庫腳本\caiwubookbak文件直接恢復數據庫這樣數據庫中存在初始的科目信息和系統參數數據數據

  後面幾小節我們將列出幾個重點的數據表的建庫腳本其他數據表的腳本請參考腳本文件

   創建科目表數據表

  創建科目表數據表的SQL腳本如下

  CREATE TABLE [dbo][科目表] (

  [科目代碼] [char] () NOT NULL

  [科目名稱] [char] () NULL

  [助記碼] [char] () NULL

  [科目類別] [char] () NULL

  [是否存貨科目] [char] () NULL

  [余額方向] [char] () NULL

  [數量單位] [char] () NULL

  ) ON [PRIMARY]

  GO

   創建憑證表分錄表數據表

  創建憑證表數據表的SQL腳本如下

  CREATE TABLE [dbo][憑證表] (

  [憑證編號] [char] () NOT NULL

  [會計期間] [int] NULL

  [憑證字號] [char] () NULL

  [日期] [datetime] NULL

  [附單據] [int] NULL

  [制單] [char] () NULL

  [借方合計] [money] NULL

  [貸方合計] [money] NULL

  [過帳狀態] [char] () NULL

  [憑證狀態] [char] () NULL

  ) ON [PRIMARY]

  GO

  創建分錄表數據表的SQL腳本如下

  CREATE TABLE [dbo][分錄表] (

  [編號] [int] IDENTITY ( ) NOT NULL

  [憑證編號] [char] () NOT NULL

  [摘要] [char] () NULL

  [科目代碼] [char] () NULL

  [借方] [money] NULL

  [貸方] [money] NULL

  [數量] [int] NULL

  [單價] [money] NULL

  [結算方式] [char] () NULL

  [結算號] [int] NULL

  [結算日期] [datetime] NULL

  ) ON [PRIMARY]

  GO

   創建其他關鍵數據表

  以下是其他關鍵數據表的創建腳本其他數據表可以參看配書光盤中的相關內容

  CREATE TABLE [dbo][科目余額表] (

  [科目代碼] [char] () NULL

  [期初借方余額] [money] NULL

  [期初貸方余額] [money] NULL

  [本期借方發生額] [money] NULL

  [本期貸方發生額] [money] NULL

  [本年借方累計發生額] [money] NULL

  [本年貸方累計發生額] [money] NULL

  [本期借方余額] [money] NULL

  [本期貸方余額] [money] NULL

  [最後結算分錄] [int] NULL

  [會計期間] [int] NULL

  [余額方向] [char] () NULL

  [內部編號] [int] IDENTITY ( ) NOT NULL

  ) ON [PRIMARY]

  GO

  CREATE TABLE [dbo][資產負債表] (

  [會計期間] [int] NOT NULL

  [現金及現金等價物] [money] NULL

  [應收帳款] [money] NULL

  [壞帳准備] [money] NULL

  [應收帳款淨值] [money] NULL

  [流動資產總計] [money] NULL

  [固定資產原值] [money] NULL

  [累計折舊] [money] NULL

  [固定資產總計] [money] NULL

  [其他資產] [money] NULL

  [資產總計] [money] NULL

  [應付帳款] [money] NULL

  [預收帳款] [money] NULL

  [應付工資] [money] NULL

  [其他負債] [money] NULL

  [負債總計] [money] NULL

  [實收資本] [money] NULL

  [資本公積] [money] NULL

  [贏余公積] [money] NULL

  [未分配利潤] [money] NULL

  [所有者權益總計] [money] NULL

  [負債及所有者權益總計] [money] NULL

  ) ON [PRIMARY]

  GO

   創建主鍵及外鍵等表約束

  在查詢分析器中通過如下代碼創建數據表的主鍵及外鍵等表約束

   主鍵外鍵關聯字段

  ALTER TABLE [dbo][科目表] WITH NOCHECK ADD

  PRIMARY KEY CLUSTERED

  (

  [科目代碼]

  ) ON [PRIMARY]

  GO

  ALTER TABLE [dbo][憑證表] WITH NOCHECK ADD

  CONSTRAINT [PK_憑證表] PRIMARY KEY CLUSTERED

  (

  [憑證編號]

  ) ON [PRIMARY]

  GO

  ALTER TABLE [dbo][分錄表] WITH NOCHECK ADD

  CONSTRAINT [PK_分錄表] PRIMARY KEY CLUSTERED

  (

  [編號]

  ) ON [PRIMARY]

  GO

  ALTER TABLE [dbo][帳簿初始化表] WITH NOCHECK ADD

  PRIMARY KEY CLUSTERED

  (

  [科目代碼]

  ) ON [PRIMARY]

  GO

  ALTER TABLE [dbo][本期匯總帳簿] WITH NOCHECK ADD

  CONSTRAINT [PK_本期匯總帳簿] PRIMARY KEY CLUSTERED

  (

  [科目代碼]

  ) ON [PRIMARY]

  GO

  ALTER TABLE [dbo][分錄表] ADD

  CONSTRAINT [FK_分錄表_憑證表] FOREIGN KEY

  (

  [憑證編號]

  ) REFERENCES [dbo][憑證表] (

  [憑證編號]

  )

  CONSTRAINT [分錄表_科目代碼_fk] FOREIGN KEY

  (

  [科目代碼]

  ) REFERENCES [dbo][科目表] (

  [科目代碼]

  )

  GO

  

  其他外鍵主鍵等約束參看配書光盤腳本


From:http://tw.wingwit.com/Article/program/Delphi/201311/24743.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.