if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_分录表_凭证表]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[分录表] DROP CONSTRAINT FK_分录表_凭证表
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[本期汇总账簿_科目代码_fk]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[本期汇总账簿] DROP CONSTRAINT 本期汇总账簿_科目代码_fk
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[本期明细账簿_科目代码_fk]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[本期明细账簿] DROP CONSTRAINT 本期明细账簿_科目代码_fk
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[分录表_科目代码_fk]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[分录表] DROP CONSTRAINT 分录表_科目代码_fk
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[分录表历史_科目代码_fk]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[分录表历史] DROP CONSTRAINT 分录表历史_科目代码_fk
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[科目余额表_科目代码_fk]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[科目余额表] DROP CONSTRAINT 科目余额表_科目代码_fk
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[帐簿初始化表_科目代码_fk]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[帐簿初始化表] DROP CONSTRAINT 帐簿初始化表_科目代码_fk
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sf_凭证过帐]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sf_凭证过帐]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sf_初始化帐户]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sf_初始化帐户]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sf_启用帐户]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sf_启用帐户]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sf_期末结帐]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sf_期末结帐]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sf_计算资产负债表]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sf_计算资产负债表]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[凭证表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[凭证表]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[凭证表历史]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[凭证表历史]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[分录表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[分录表]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[分录表历史]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[分录表历史]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[帐簿初始化表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[帐簿初始化表]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[本期明细账簿]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[本期明细账簿]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[本期汇总账簿]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[本期汇总账簿]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[科目余额表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[科目余额表]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[科目表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[科目表]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[系统参数表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[系统参数表]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[资产负债表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[资产负债表]
GO
CREATE TABLE [dbo].[凭证表] (
[凭证编号] [char] (10) NOT NULL ,
[会计期间] [int] NULL ,
[凭证字号] [cha�