Skip to main content
Tweeted twitter.com/StackDBAs/status/784231162617233409
added a tag = sql-server
Link
Marcello Miorelli
  • 16.6k
  • 53
  • 170
  • 311
incorporated comment
Source Link
Tom V
  • 15.7k
  • 7
  • 64
  • 87

After applying my database changes on the test environment, the test team starts testing their processes, one of the things I get is a truncate table error because the table is used in an indexed view.

    (1 row(s) affected)
    ProductIconTypes ending
    ProductImageCategories starting
    Msg 3729, Level 16, State 2, Line 1
    Cannot TRUNCATE TABLE 'dbo.ProductImageCategories' 
because it is being referenced by object 'VWProductImageGetByStyle'.

Questions:

  1. next time I want to put an indexed view on one of my databases what exactly I should be checking?

  2. Can I get this done through my favourite route (T-SQL)?

I would not mind powershell either.

unfortunatelyUnfortunately on these servers in question we are still on sqlSQL Server 2005 AND sqlSQL Server 2008 R2.

A Comment:

theseThese versions impose a lot of limitations on things that we can do as alternatives. Filtered indexes for instance are not available on sqlSQL Server 2005.

I am actually looking for a way if possible to find out what would stop working if I created this indexed view. In my example, the truncate tables could no longer work.

After applying my database changes on the test environment, the test team starts testing their processes, one of the things I get is a truncate table error because the table is used in an indexed view.

    (1 row(s) affected)
    ProductIconTypes ending
    ProductImageCategories starting
    Msg 3729, Level 16, State 2, Line 1
    Cannot TRUNCATE TABLE 'dbo.ProductImageCategories' 
because it is being referenced by object 'VWProductImageGetByStyle'.

Questions:

  1. next time I want to put an indexed view on one of my databases what exactly I should be checking?

  2. Can I get this done through my favourite route (T-SQL)?

I would not mind powershell either.

unfortunately on these servers in question we are still on sql 2005 AND sql 2008 R2.

A Comment:

these versions impose a lot of limitations on things that we can do as alternatives. Filtered indexes for instance are not available on sql 2005.

After applying my database changes on the test environment, the test team starts testing their processes, one of the things I get is a truncate table error because the table is used in an indexed view.

    (1 row(s) affected)
    ProductIconTypes ending
    ProductImageCategories starting
    Msg 3729, Level 16, State 2, Line 1
    Cannot TRUNCATE TABLE 'dbo.ProductImageCategories' 
because it is being referenced by object 'VWProductImageGetByStyle'.

Questions:

  1. next time I want to put an indexed view on one of my databases what exactly I should be checking?

  2. Can I get this done through my favourite route (T-SQL)?

I would not mind powershell either.

Unfortunately on these servers in question we are still on SQL Server 2005 AND SQL Server 2008 R2.

A Comment:

These versions impose a lot of limitations on things that we can do as alternatives. Filtered indexes for instance are not available on SQL Server 2005.

I am actually looking for a way if possible to find out what would stop working if I created this indexed view. In my example, the truncate tables could no longer work.

Source Link
Marcello Miorelli
  • 16.6k
  • 53
  • 170
  • 311

T-SQL to check whether or not a indexed view can be created on tableX?

After applying my database changes on the test environment, the test team starts testing their processes, one of the things I get is a truncate table error because the table is used in an indexed view.

    (1 row(s) affected)
    ProductIconTypes ending
    ProductImageCategories starting
    Msg 3729, Level 16, State 2, Line 1
    Cannot TRUNCATE TABLE 'dbo.ProductImageCategories' 
because it is being referenced by object 'VWProductImageGetByStyle'.

Questions:

  1. next time I want to put an indexed view on one of my databases what exactly I should be checking?

  2. Can I get this done through my favourite route (T-SQL)?

I would not mind powershell either.

unfortunately on these servers in question we are still on sql 2005 AND sql 2008 R2.

A Comment:

these versions impose a lot of limitations on things that we can do as alternatives. Filtered indexes for instance are not available on sql 2005.