Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8080193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:20:26+00:00 2026-06-05T16:20:26+00:00

My table structure is below: CREATE TABLE [ACC].[Document]( [DocumentID] [int] IDENTITY(1,1) NOT NULL, [Date]

  • 0

My table structure is below:

CREATE TABLE [ACC].[Document](
    [DocumentID] [int] IDENTITY(1,1) NOT NULL,
    [Date] [date] NOT NULL,
    [SalesCompanyFinancialPeriodID] [int] NOT NULL,
    [DocumentTypeID] [int] NULL,
 CONSTRAINT [PK_Document] PRIMARY KEY CLUSTERED 
(
    [DocumentID] ASC
)

I want to partitioning my table on SalesCompanyFinancialPeriodID column. is it possible to DocumentID column value reset on each partition. in other word DocumentID in each partition wat independent by DocumentID in other partition.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:20:27+00:00Added an answer on June 5, 2026 at 4:20 pm

    Depending on your exact criteria you could create a view if the reference numbers are only needed on the fly:

    CREATE VIEW Acc.PartitionedDocument
    AS
        SELECT  DocumentID,
                Date,
                SalesCompanyFinancialPeriod,
                DocumentTypeID,
                ROW_NUMBER() OVER(PARTITION BY SalesCompanyFinancialPeriod ORDER BY DocumentID) [PartitionDocumentID]
        FROM    Acc.Document
    

    However, this will change if documents are deleted. Otherwise your only alternative as far as I am aware with SQL-Server 2008 is to maintain a sequence either with a trigger or within your application layer. Below is how I would achieve this with a trigger.

    -- ADD ADDITIONAL COLUMN
    ALTER TABLE Acc.Document ADD ParitionDocumentID INT NULL
    GO
    -- UPDATE EXISTING ROWS
    ;WITH Doc AS
    (   SELECT  *, ROW_NUMBER() OVER(PARTITION BY SalesCompanyFinancialPeriod ORDER BY DocumentID) [RowNumber]
        FROM    Acc.Document
    )
    UPDATE  Doc
    SET     PartitionDocumentID = RowNumber
    
    GO
    -- ADD CONSTRAINT TO ENSURE NO DUPLICATES
    ALTER TABLE Acc.Document ADD CONSTRAINT UQ_Acc_Document UNIQUE NONCLUSTERED (PartitionDocumentID, SalesCompanyFinancialPeriodID)
    GO
    -- ADD TRIGGER TO MAINTAIN NEW COLUMN
    CREATE TRIGGER acc.InsertDocument
    ON Acc.Document
    FOR INSERT 
    AS
        IF EXISTS(SELECT 1 FROM inserted WHERE PartitionDocumentID IS NULL)
            BEGIN
    
                UPDATE  Acc.Document
                SET     PartitionDocumentID = COALESCE(NextDocumentID, 0) + RowNumber
                FROM    Acc.Document d
                        INNER JOIN 
                        (   SELECT  DocumentID, ROW_NUMBER() OVER(PARTITION BY SalesCompanyFinancialPeriodID ORDER BY DocumentID) [RowNumber]
                            FROM    inserted 
                            WHERE   PartitionDocumentID IS NULL
                        ) i
                            ON i.DocumentID = d.DocumentID
                        LEFT JOIN
                        (   SELECT  SalesCompanyFinancialPeriodID, MAX(PartitionDocumentID)  [NextDocumentID]
                            FROM    Acc.Document
                            GROUP BY SalesCompanyFinancialPeriodID
                        ) NextID
                            ON NextID.SalesCompanyFinancialPeriodID = d.SalesCompanyFinancialPeriodID
            END
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
My table structure is as shown below CREATE TABLE MCARE_HOUSE_DETAILS ( HOUSE_DTL_ID VARCHAR(20) NOT
My table structure is below : MyTable (ID Int, AccID1 Int, AccID2 Int, AccID3
I have a table with below structure. I am not having control over changing
Table structure- int PrimaryKey DateTime Date int Price What I would like to do
Based on the following data structure. CREATE TABLE [Parent] ( Id INT, Name nvarchar(100)
I have a organization name table with the following structure given below: CREATE TABLE
newb question there. Having MySQL database/tables structure below: CREATE DATABASE `dbTest` CREATE TABLE IF
Using the table structure below how would I create a bcp bulk insert that
I have a below table structure for friends table TABLE STRUCTURE CREATE TABLE `my_friends`

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.