JULU
Гость
|
|
« Ответ #3 : 08-04-2007 18:28 » |
|
Код для создания таблиц таблица BOOKS USE [Bookshop ] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Books]( [BookID] [int] NOT NULL, [Title] [nchar](10) COLLATE Cyrillic_General_CI_AS NULL, [GenreID] [int] NOT NULL, [Author] [nvarchar](50) COLLATE Cyrillic_General_CI_AS NOT NULL, [PurchasingPrice] [money] NOT NULL, [RetailPrice] AS (([PurchasingPrice]/(100))*(15)+[PurchasingPrice]) PERSISTED, [PageNumber] [int] NULL, [PublicationDate] [datetime] NULL, [QuantityBegin] [int] NULL, [CoverStyle] [nchar](10) COLLATE Cyrillic_General_CI_AS NOT NULL, [Description] [nvarchar](500) COLLATE Cyrillic_General_CI_AS NOT NULL CONSTRAINT [DF_Books_Description] DEFAULT ('Нет описания'), [ModifiedDate] [datetime] NOT NULL CONSTRAINT [DF_Books_ModifiedDate] DEFAULT (getdate()), [PublishingHouseID] [int] NULL, CONSTRAINT [PK_Books] PRIMARY KEY CLUSTERED ( [BookID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY]
GO SET ANSI_PADDING OFF GO USE [Bookshop ] GO
таблица Purchase USE [Bookshop ] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[Purchase1]( [PurchasingID] [int] NOT NULL, [BookID] [int] NOT NULL, [Quantity] [int] NOT NULL, [PurchasingHouseID] [int] NOT NULL, CONSTRAINT [PK_Purchase1] PRIMARY KEY CLUSTERED ( [PurchasingID] ASC )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY]
GO USE [Bookshop ] GO ALTER TABLE [dbo].[Purchase1] WITH CHECK ADD CONSTRAINT [FK_Purchase1_Books] FOREIGN KEY([BookID]) REFERENCES [dbo].[Books] ([BookID])
триггер: USE [Bookshop ] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TRIGGER [BookPurchases1] ON [dbo].[Purchase1] for INSERT AS BEGIN SET NOCOUNT on; update t set t.[QuantityBegin]=t.[QuantityBegin]+i.Quantity from dbo.Books t inner join inserted i on t.[BookID]=i.[BookID] END
Таблица Purchase связана с Books как 1 к многим.
|