if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Demo_Items]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Demo_Items]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Demo_Receipt]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Demo_Receipt]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Demo_ReceiptDetail]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[Demo_ReceiptDetail]
GO

CREATE TABLE [dbo].[Demo_Items] (
	[ItemID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[fcItemCode] [nvarchar] (4) COLLATE Chinese_PRC_CI_AS NULL ,
	[fcItemName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[fcUnit] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[fnPrice] [numeric](18, 2) NULL ,
	[fcRemark] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Demo_Receipt] (
	[ID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[fcReceiptNo] [nvarchar] (15) COLLATE Chinese_PRC_CI_AS NULL ,
	[fcChecker] [nvarchar] (8) COLLATE Chinese_PRC_CI_AS NULL ,
	[fcOperator] [nvarchar] (8) COLLATE Chinese_PRC_CI_AS NULL ,
	[fdMakeDate] [datetime] NULL ,
	[fcMemo] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[Demo_ReceiptDetail] (
	[DetailSn] [int] IDENTITY (1, 1) NOT NULL ,
	[DetailID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[fcReceiptNo] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL ,
	[fgItemID] [uniqueidentifier] NULL ,
	[fnPrice] [numeric](18, 2) NULL ,
	[fnTaxRate] [numeric](18, 0) NULL ,
	[fnTaxPrice] [numeric](18, 2) NULL ,
	[fnQuantity] [numeric](18, 0) NULL ,
	[fnAmount] [numeric](18, 2) NULL ,
	[fnTaxAmount] [numeric](18, 2) NULL ,
	[fcRemark] [nvarchar] (255) COLLATE Chinese_PRC_CI_AS NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[Demo_Items] WITH NOCHECK ADD 
	CONSTRAINT [DF_Demo_Items_ItemID] DEFAULT (newid()) FOR [ItemID],
	CONSTRAINT [DF_Demo_Items_fnPrice] DEFAULT (0) FOR [fnPrice],
	CONSTRAINT [PK_Demo_Items] PRIMARY KEY  CLUSTERED 
	(
		[ItemID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Demo_Receipt] WITH NOCHECK ADD 
	CONSTRAINT [DF_Demo_Receipt_ID] DEFAULT (newid()) FOR [ID],
	CONSTRAINT [DF_Demo_Receipt_fcChecker] DEFAULT ('周方勇') FOR [fcChecker],
	CONSTRAINT [DF_Demo_Receipt_fdMakeDate] DEFAULT (getdate()) FOR [fdMakeDate],
	CONSTRAINT [PK_Demo_Receipt] PRIMARY KEY  CLUSTERED 
	(
		[ID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[Demo_ReceiptDetail] WITH NOCHECK ADD 
	CONSTRAINT [DF_Demo_ReceiptDetail_DetailID] DEFAULT (newid()) FOR [DetailID],
	CONSTRAINT [PK_Demo_ReceiptDetail] PRIMARY KEY  CLUSTERED 
	(
		[DetailID]
	)  ON [PRIMARY] 
GO


exec sp_addextendedproperty N'MS_Description', N'商品编号', N'user', N'dbo', N'table', N'Demo_Items', N'column', N'fcItemCode'
GO
exec sp_addextendedproperty N'MS_Description', N'商品名', N'user', N'dbo', N'table', N'Demo_Items', N'column', N'fcItemName'
GO
exec sp_addextendedproperty N'MS_Description', N'小注', N'user', N'dbo', N'table', N'Demo_Items', N'column', N'fcRemark'
GO
exec sp_addextendedproperty N'MS_Description', N'单位', N'user', N'dbo', N'table', N'Demo_Items', N'column', N'fcUnit'
GO
exec sp_addextendedproperty N'MS_Description', N'单价，可以设置小数位', N'user', N'dbo', N'table', N'Demo_Items', N'column', N'fnPrice'


GO


exec sp_addextendedproperty N'MS_Description', N'审核人，不作关联', N'user', N'dbo', N'table', N'Demo_Receipt', N'column', N'fcChecker'
GO
exec sp_addextendedproperty N'MS_Description', N'备注', N'user', N'dbo', N'table', N'Demo_Receipt', N'column', N'fcMemo'
GO
exec sp_addextendedproperty N'MS_Description', N'审核人，不作关联', N'user', N'dbo', N'table', N'Demo_Receipt', N'column', N'fcOperator'
GO
exec sp_addextendedproperty N'MS_Description', N'单据编号', N'user', N'dbo', N'table', N'Demo_Receipt', N'column', N'fcReceiptNo'
GO
exec sp_addextendedproperty N'MS_Description', N'操作日期', N'user', N'dbo', N'table', N'Demo_Receipt', N'column', N'fdMakeDate'
GO
exec sp_addextendedproperty N'MS_Description', N'主键，GUID，全球唯一，并于数据合并', N'user', N'dbo', N'table', N'Demo_Receipt', N'column', N'ID'


GO


exec sp_addextendedproperty N'MS_Description', N'记录一张单据保存时明细先后顺序，无其它意义', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'DetailSn'
GO
exec sp_addextendedproperty N'MS_Description', N'单据编号，与主表关联', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fcReceiptNo'
GO
exec sp_addextendedproperty N'MS_Description', N'小注', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fcRemark'
GO
exec sp_addextendedproperty N'MS_Description', N'商品项，外键', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fgItemID'
GO
exec sp_addextendedproperty N'MS_Description', N'实际发生的金额，一般为数量*单价', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fnAmount'
GO
exec sp_addextendedproperty N'MS_Description', N'实际发生单价，而不是商品的参考价', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fnPrice'
GO
exec sp_addextendedproperty N'MS_Description', N'数量', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fnQuantity'
GO
exec sp_addextendedproperty N'MS_Description', N'实际发生的税价小计，一般为数量*含税单价', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fnTaxAmount'
GO
exec sp_addextendedproperty N'MS_Description', N'含税价', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fnTaxPrice'
GO
exec sp_addextendedproperty N'MS_Description', N'税率', N'user', N'dbo', N'table', N'Demo_ReceiptDetail', N'column', N'fnTaxRate'


GO

