Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL - reset cumulative value while keeping historical data
    primarykey
    data
    text
    <p>I've been encharged, during my university internship, to create a web application to manage maintenace operations in the factory I work in. I'm an industrial engineer with just a little knowledge about database programming, so maybe this question will sound easy to you, I apologize. </p> <p>That's the situation: the item is a mold, which needs ordinary maintenance after a number of operations (huge number, I'm talking about tiles manufacturing, and the maintenance frequency can be assumed as a mean value of once per year). I set up a database and the web application connected to it, and I created a view with the molds' list and the relative cumulative work, so that the department's responsible can have a fast perspective of the situation and see which molds need maintenance, and that works fine.</p> <p>The problem is they "labeled" the molds, and I used that number as the row ID in the database. When the maintenance is performed the cumulative work needs to be resetted, but he wants to keep historical data about working operations. </p> <p>Thus, what I need to do now, is "tell the system" when an item is manteined, then it has to reset the cumulative value while keeping historical data.</p> <p>Values for the view I created are taken from 2 different tables: Molds and UnmountingOperations. In the latter there are information about which press the mold has been mounted on and the total work done during that operation. I thougt the solution is in the use of triggers, but I'd would like to ask:</p> <p>What's the best practice to do so?</p> <p>here you are the scripts created by SqlServer management studio.Sorry but record names are in Italian. mold table:</p> <pre><code>CREATE TABLE [dbo].[Stampo]( [ID] [int] NOT NULL, [Formato] [nchar](10) NOT NULL, [n∞ uscite] [int] NULL, [Spessore] [nchar](10) NULL, [Descrizione] [nvarchar](max) NULL, [Fornitore] [nvarchar](50) NULL, CONSTRAINT [PK_Stampo] PRIMARY KEY CLUSTERED ( [ID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] </code></pre> <p>press table:</p> <pre><code>CREATE TABLE [dbo].[Pressa]( [Numero] [int] NOT NULL, [Modello] [nchar](10) NULL, CONSTRAINT [PK_Pressa] PRIMARY KEY CLUSTERED ( [Numero] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] </code></pre> <p>association mold-press for unmounting operations(mq_pressati) is the work amount driver,stands for square meters pressed:</p> <pre><code>CREATE TABLE [dbo].[SmontaggioStampi]( [NumeroPressa] [int] NOT NULL, [IDStampo] [int] NOT NULL, [DataSmontaggio] [datetime] NOT NULL, [mq_pressati] [int] NOT NULL, [Descrizione] [nvarchar](max) NULL, CONSTRAINT [PK_Produzione presse] PRIMARY KEY CLUSTERED ( [NumeroPressa] ASC, [IDStampo] ASC, [DataSmontaggio] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[SmontaggioStampi] WITH CHECK ADD CONSTRAINT [FK_SmontaggioStampi_Pressa] FOREIGN KEY([NumeroPressa]) REFERENCES [dbo].[Pressa] ([Numero]) GO ALTER TABLE [dbo].[SmontaggioStampi] CHECK CONSTRAINT [FK_SmontaggioStampi_Pressa] GO ALTER TABLE [dbo].[SmontaggioStampi] WITH CHECK ADD CONSTRAINT [FK_SmontaggioStampi_Stampo] FOREIGN KEY([IDStampo]) REFERENCES [dbo].[Stampo] ([ID]) GO ALTER TABLE [dbo].[SmontaggioStampi] CHECK CONSTRAINT [FK_SmontaggioStampi_Stampo] GO </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload