Forum Posts

GROUP BY CUBE example

The GROUP BY CUBE statement is pretty sweet. Here’s an example.

First, let’s create our table and add data:

IF EXISTS (SELECT * FROM sys.objects
WHERE object_id = OBJECT_ID(N’[dbo].[GroupByCubeExample]‘)
AND type in (N’U'))
DROP TABLE [dbo].[GroupByCubeExample]
GO

CREATE TABLE [dbo].[GroupByCubeExample](
[Region] [nvarchar](50) NOT NULL,
[Product] [nvarchar](50) NOT NULL,
[Salesman] [nvarchar](50) NOT NULL,
[Amount] [money] NOT NULL
)
GO

INSERT INTO dbo.GroupByCubeExample
(Region,Product,Salesman,Amount)
SELECT ‘America’,'Bike’,'Bean, Adam’,10
UNION ALL SELECT ‘America’,'Bike’,'Stanford, Matt’,20
UNION [...]

“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created.”

Management Studio 2008 has a default that prevents saving table changes from the designer when the table will need to be rebuilt.  I’m constantly being asked about this error by developers:

 ”Saving changes is not permitted.  The changes you have made require the following tables to be dropped and re-created.”

 To be able to make table changes [...]