根據實例介紹
打開SQL Server企業管理器
後面幾小節我們將列出幾個重點的數據表的建庫腳本
創建
CREATE TABLE [dbo]
[科目代碼] [char] (
[科目名稱] [char] (
[助記碼] [char] (
[科目類別] [char] (
[是否存貨科目] [char] (
[余額方向] [char] (
[數量單位] [char] (
) ON [PRIMARY]
GO
創建
CREATE TABLE [dbo]
[憑證編號] [char] (
[會計期間] [int] NULL
[憑證字號] [char] (
[日期] [datetime] NULL
[附單據] [int] NULL
[制單] [char] (
[借方合計] [money] NULL
[貸方合計] [money] NULL
[過帳狀態] [char] (
[憑證狀態] [char] (
) ON [PRIMARY]
GO
創建
CREATE TABLE [dbo]
[編號] [int] IDENTITY (
[憑證編號] [char] (
[摘要] [char] (
[科目代碼] [char] (
[借方] [money] NULL
[貸方] [money] NULL
[數量] [int] NULL
[單價] [money] NULL
[結算方式] [char] (
[結算號] [int] NULL
[結算日期] [datetime] NULL
) ON [PRIMARY]
GO
以下是其他關鍵數據表的創建腳本
CREATE TABLE [dbo]
[科目代碼] [char] (
[期初借方余額] [money] NULL
[期初貸方余額] [money] NULL
[本期借方發生額] [money] NULL
[本期貸方發生額] [money] NULL
[本年借方累計發生額] [money] NULL
[本年貸方累計發生額] [money] NULL
[本期借方余額] [money] NULL
[本期貸方余額] [money] NULL
[最後結算分錄] [int] NULL
[會計期間] [int] NULL
[余額方向] [char] (
[內部編號] [int] IDENTITY (
) 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]
PRIMARY KEY CLUSTERED
(
[科目代碼]
) ON [PRIMARY]
GO
ALTER TABLE [dbo]
CONSTRAINT [PK_憑證表] PRIMARY KEY CLUSTERED
(
[憑證編號]
) ON [PRIMARY]
GO
ALTER TABLE [dbo]
CONSTRAINT [PK_分錄表] PRIMARY KEY CLUSTERED
(
[編號]
) ON [PRIMARY]
GO
ALTER TABLE [dbo]
PRIMARY KEY CLUSTERED
(
[科目代碼]
) ON [PRIMARY]
GO
ALTER TABLE [dbo]
CONSTRAINT [PK_本期匯總帳簿] PRIMARY KEY CLUSTERED
(
[科目代碼]
) ON [PRIMARY]
GO
ALTER TABLE [dbo]
CONSTRAINT [FK_分錄表_憑證表] FOREIGN KEY
(
[憑證編號]
) REFERENCES [dbo]
[憑證編號]
)
CONSTRAINT [分錄表_科目代碼_fk] FOREIGN KEY
(
[科目代碼]
) REFERENCES [dbo]
[科目代碼]
)
GO
其他外鍵
From:http://tw.wingwit.com/Article/program/Delphi/201311/24743.html