Script to replace All Existing Clustered Primary Keys to Columnstore indexes Announcing the...

What would be the ideal power source for a cybernetic eye?

Do I really need recursive chmod to restrict access to a folder?

What is the musical term for a note that continously plays through a melody?

Does surprise arrest existing movement?

Is there a Spanish version of "dot your i's and cross your t's" that includes the letter 'ñ'?

Bonus calculation: Am I making a mountain out of a molehill?

Letter Boxed validator

Right-skewed distribution with mean equals to mode?

What is a Meta algorithm?

How do I stop a creek from eroding my steep embankment?

Gastric acid as a weapon

If a contract sometimes uses the wrong name, is it still valid?

Why are there no cargo aircraft with "flying wing" design?

What do you call a phrase that's not an idiom yet?

Storing hydrofluoric acid before the invention of plastics

Why constant symbols in a language?

Why does Python start at index -1 when indexing a list from the end?

Should I discuss the type of campaign with my players?

If Jon Snow became King of the Seven Kingdoms what would his regnal number be?

Are my PIs rude or am I just being too sensitive?

Is 1 ppb equal to 1 μg/kg?

Should I call the interviewer directly, if HR aren't responding?

How to deal with a team lead who never gives me credit?

Stars Make Stars



Script to replace All Existing Clustered Primary Keys to Columnstore indexes



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Why is Clustered Index on Primary Key compulsory?Clustered columnstore indexes and foreign keysSimple query is slow on 4M-rows tableChange clustered index without dropping the primary keydeteriorating stored procedure running timesDrawbacks to add clustered keysNon-Unique Clustered Indexes AdministrationClustered Primary Key that is never used vs. Non-Clustered Primary Key on Multiple ColumnsClustered vs Non Clustered Indexes for a Primary KeyClustered Sequential GUID Primary Key vs Non-Clustered GUID and Clustered Sequential ID Primary Keys





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







0















Does anyone have a script to replace all existing All Existing Clustered Primary Keys to Clustered Columnstore indexes in a table? We have 500 plus tables in a database.



CREATE TABLE [dbo].[Purchase] 
(
[PurchaseId] INT IDENTITY (1, 1) NOT NULL,
[ClientId] INT NOT NULL,
[SellerId] INT NOT NULL,
[PurchaseDatetime] DATETIME NULL,
[TotalAmount] DECIMAL (28, 2) NULL,
[CreateDate] DATETIME NULL,
CONSTRAINT [pk_PurchaseId] PRIMARY KEY CLUSTERED ([PurchaseId] ASC)
);


Expected:



CREATE TABLE [dbo].[Purchase] 
(
[PurchaseId] INT IDENTITY (1, 1) NOT NULL,
[ClientId] INT NOT NULL,
[SellerId] INT NOT NULL,
[PurchaseDatetime] DATETIME NULL,
[TotalAmount] DECIMAL (28, 2) NULL,
[CreateDate] DATETIME NULL
);


CREATE CLUSTERED COLUMNSTORE INDEX clx_Purchase ON dbo.Purchase;

CREATE UNIQUE INDEX uq_PurchaseIdId ON dbo.Purchase(PurchaseId);


we don't have foreign keys.









share







New contributor




TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.



























    0















    Does anyone have a script to replace all existing All Existing Clustered Primary Keys to Clustered Columnstore indexes in a table? We have 500 plus tables in a database.



    CREATE TABLE [dbo].[Purchase] 
    (
    [PurchaseId] INT IDENTITY (1, 1) NOT NULL,
    [ClientId] INT NOT NULL,
    [SellerId] INT NOT NULL,
    [PurchaseDatetime] DATETIME NULL,
    [TotalAmount] DECIMAL (28, 2) NULL,
    [CreateDate] DATETIME NULL,
    CONSTRAINT [pk_PurchaseId] PRIMARY KEY CLUSTERED ([PurchaseId] ASC)
    );


    Expected:



    CREATE TABLE [dbo].[Purchase] 
    (
    [PurchaseId] INT IDENTITY (1, 1) NOT NULL,
    [ClientId] INT NOT NULL,
    [SellerId] INT NOT NULL,
    [PurchaseDatetime] DATETIME NULL,
    [TotalAmount] DECIMAL (28, 2) NULL,
    [CreateDate] DATETIME NULL
    );


    CREATE CLUSTERED COLUMNSTORE INDEX clx_Purchase ON dbo.Purchase;

    CREATE UNIQUE INDEX uq_PurchaseIdId ON dbo.Purchase(PurchaseId);


    we don't have foreign keys.









    share







    New contributor




    TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      Does anyone have a script to replace all existing All Existing Clustered Primary Keys to Clustered Columnstore indexes in a table? We have 500 plus tables in a database.



      CREATE TABLE [dbo].[Purchase] 
      (
      [PurchaseId] INT IDENTITY (1, 1) NOT NULL,
      [ClientId] INT NOT NULL,
      [SellerId] INT NOT NULL,
      [PurchaseDatetime] DATETIME NULL,
      [TotalAmount] DECIMAL (28, 2) NULL,
      [CreateDate] DATETIME NULL,
      CONSTRAINT [pk_PurchaseId] PRIMARY KEY CLUSTERED ([PurchaseId] ASC)
      );


      Expected:



      CREATE TABLE [dbo].[Purchase] 
      (
      [PurchaseId] INT IDENTITY (1, 1) NOT NULL,
      [ClientId] INT NOT NULL,
      [SellerId] INT NOT NULL,
      [PurchaseDatetime] DATETIME NULL,
      [TotalAmount] DECIMAL (28, 2) NULL,
      [CreateDate] DATETIME NULL
      );


      CREATE CLUSTERED COLUMNSTORE INDEX clx_Purchase ON dbo.Purchase;

      CREATE UNIQUE INDEX uq_PurchaseIdId ON dbo.Purchase(PurchaseId);


      we don't have foreign keys.









      share







      New contributor




      TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      Does anyone have a script to replace all existing All Existing Clustered Primary Keys to Clustered Columnstore indexes in a table? We have 500 plus tables in a database.



      CREATE TABLE [dbo].[Purchase] 
      (
      [PurchaseId] INT IDENTITY (1, 1) NOT NULL,
      [ClientId] INT NOT NULL,
      [SellerId] INT NOT NULL,
      [PurchaseDatetime] DATETIME NULL,
      [TotalAmount] DECIMAL (28, 2) NULL,
      [CreateDate] DATETIME NULL,
      CONSTRAINT [pk_PurchaseId] PRIMARY KEY CLUSTERED ([PurchaseId] ASC)
      );


      Expected:



      CREATE TABLE [dbo].[Purchase] 
      (
      [PurchaseId] INT IDENTITY (1, 1) NOT NULL,
      [ClientId] INT NOT NULL,
      [SellerId] INT NOT NULL,
      [PurchaseDatetime] DATETIME NULL,
      [TotalAmount] DECIMAL (28, 2) NULL,
      [CreateDate] DATETIME NULL
      );


      CREATE CLUSTERED COLUMNSTORE INDEX clx_Purchase ON dbo.Purchase;

      CREATE UNIQUE INDEX uq_PurchaseIdId ON dbo.Purchase(PurchaseId);


      we don't have foreign keys.







      sql-server performance sql-server-2017 columnstore





      share







      New contributor




      TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share







      New contributor




      TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share



      share






      New contributor




      TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 1 min ago









      TomBookTomBook

      1




      1




      New contributor




      TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      TomBook is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          0






          active

          oldest

          votes












          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "182"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          TomBook is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234865%2fscript-to-replace-all-existing-clustered-primary-keys-to-columnstore-indexes%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          TomBook is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          TomBook is a new contributor. Be nice, and check out our Code of Conduct.













          TomBook is a new contributor. Be nice, and check out our Code of Conduct.












          TomBook is a new contributor. Be nice, and check out our Code of Conduct.
















          Thanks for contributing an answer to Database Administrators Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f234865%2fscript-to-replace-all-existing-clustered-primary-keys-to-columnstore-indexes%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Anexo:Material bélico de la Fuerza Aérea de Chile Índice Aeronaves Defensa...

          Always On Availability groups resolving state after failover - Remote harden of transaction...

          update json value to null Announcing the arrival of Valued Associate #679: Cesar Manara ...