Move an existing Clustered columnstore index into a different file group - sql

I am trying to move an existing Clustered Columnstore Index from one file group to another file group but couldn't find any command to do that.
Code what I have tried:
ALTER TABLE CCSI ON [dbo].[t179_s1_LOSS_ByEvent_ORIGINAL_440F6776-6185-4416-89D8-B69334457B25]
WITH ( MOVE TO FG_1 );
Error:
Msg 156, Level 15, State 1, Line 281
Incorrect syntax near the keyword 'ON'.
Msg 319, Level 15, State 1, Line 281
Incorrect syntax near the keyword 'with'. If this statement is a common table expression, an xmlnamespaces clause or a change tracking context clause, the previous statement must be terminated with a semicolon.

Just like a clustered index, recreate it on the target filegroup with DROP_EXISTING. eg
create table foo(id int, a int)
create clustered columnstore index cci_foo on foo
go
create clustered columnstore index cci_foo
on foo
with (drop_existing=on)
on fg2

Related

How to Fix Error Msg 41337, Level 16, State 100 in Create Memory Optimize table in SQL Server

I want to use a memory optimize table and I got below error - how can I fix it? Any idea will be helpful.
Msg 41337, Level 16, State 100, Line 1
Cannot create memory optimized tables. To create memory optimized tables, the database must have a MEMORY_OPTIMIZED_FILEGROUP that is online and has at least one container.
Code:
CREATE TABLE dbo.Account
(
AccountID INT IDENTITY(1, 1) PRIMARY KEY NONCLUSTERED
) WITH (MEMORY_OPTIMIZED=ON)
you must create a file Group first :
Create FileGroup :
imoltp is a sampledatabase
ALTER DATABASE imoltp ADD FILEGROUP imoltp_mod
CONTAINS MEMORY_OPTIMIZED_DATA;
Add DatabaseFile To Your File Group :
ALTER DATABASE imoltp ADD FILE (
name='imoltp_mod1', filename='c:\data\imoltp_mod1')
TO FILEGROUP imoltp_mod;
Create Memory Optimize Table:
CREATE TABLE dbo.Account(
AccountID INT IDENTITY(1,1) PRIMARY KEY NONCLUSTERED
) WITH (MEMORY_OPTIMIZED=ON)
take a look at this for get more Info :
https://learn.microsoft.com/en-us/sql/relational-databases/in-memory-oltp/creating-a-memory-optimized-table-and-a-natively-compiled-stored-procedure?view=sql-server-ver15
for more detail

SQL Server 2012 - Queries working executed one on one, but not in a group

I have been trying to execute these two queries together:
ALTER TABLE afm.owned_properties_rpt_table
ALTER COLUMN bl_id CHAR(8) NOT NULL;
ALTER TABLE afm.owned_properties_rpt_table
ADD CONSTRAINT owned_properties_rpt_table_PK PRIMARY KEY (bl_id);
But I'm getting this error:
Mens. 8111, Nivel 16, Estado 1, Línea 3
Cannot define PRIMARY KEY constraint on nullable column in table
'owned_properties_rpt_table'.
Mens. 1750, Nivel 16, Estado 0, Línea 3
Could not create constraint. See previous errors.
It seems that somehow, the second line is being executed before the first one finishes.
I have tried changing semicolons by goes, using a begin transaction/commit transaction structure, and creating an auxiliary column where I copied the data in bl_id and then dropped the old column, all of them without success.
The SQL script needs to be executed on a client's server (where I can not intervene), so dividing the code is not an alternative.
I am sorry if I am missing something elementary, I have also searched for the same problem during several hours without success.
Thanks for your help.
Try this
ALTER TABLE afm.owned_properties_rpt_table ALTER COLUMN bl_id CHAR(8) NOT NULL default 'sometest';
GO
ALTER TABLE afm.owned_properties_rpt_table ADD CONSTRAINT owned_properties_rpt_table_PK PRIMARY KEY (bl_id);

Why receiving a SYNTAX error while ALTERing a SQL table

I have an existing SQL table and I am trying to add two more columns like this:
ALTER TABLE DSPCONTENT01.dbo.RADRESULTSTOTALS2
ADD ([TEST1] INT,
[TEST2] INT);
I get the following error:
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '('.
How do I resolve it?
Don't use parentheses.
ALTER TABLE DSPCONTENT01.dbo.RADRESULTSTOTALS2
ADD
[TEST1] INT,
[TEST2] INT

Msg 5074, Level 16, State 1, Line 1 The index 'IX_Alias_Alias' is dependent on column 'Alias'

Want to change the collation
using the below script
ALTER TABLE Alias ALTER COLUMN Alias nvarchar(25) COLLATE SQL_Latin1_General_CP1256_CI_AS
Error occurs
Msg 5074, Level 16, State 1, Line 1
The index 'IX_Alias_Alias' is dependent on column 'Alias'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN Alias failed because one or more objects access this column.
Actually I want to change the collation of all the table in database
You can use the below link to alter the collation of all the objects in a database.
Alter Collation for all the objects in a DB
You should delete the index first and then modify the column.

How do I drop a column with object dependencies in SQL Server 2008?

The error message I'm obtaining when trying to drop a column:
The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.
Msg 5074, Level 16, State 1, Line 43
ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column.
I have already tried to find the default constraints, as described here:
SQL Server 2005 drop column with constraints
Unfortunately without any success :( The line returned is:
fkKeywordRolleKontakt 2 814625945 0 defEmptyString
And I cannot remove either of fkKeywordRolleKontakt and defEmptyString.
What is the correct way to get rid of this dependency?
EDIT: Perhaps this is of importance too. The column fkKeywordRolleKontakt is of type udKeyword (nvarchar(50)) with default dbo.defEmptyString.
Edit 2: Solved
I could solve the problem now. I'm sorry, I did not copy the full error message, which was:
Msg 5074, Level 16, State 1, Line 1
The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.
Msg 5074, Level 16, State 1, Line 1
The object 'FK_tlkpRolleKontakt_tlkpKeyword' is dependent on column 'fkKeywordRolleKontakt'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or more objects access this column.
I could generate a script to drop the column by right-clicking on the column entry (dbo.tlkpRolleKontakt > Columns > fkKeywordRolleKontakt) (in MSSQL Server Manager), selecting Modify and deleting the column. Then Table Designer > Generate Change Script generated the necessary commands:
ALTER TABLE dbo.tlkpRolleKontakt
DROP CONSTRAINT FK_tlkpRolleKontakt_tlkpKeyword
EXECUTE sp_unbindefault N'dbo.tlkpRolleKontakt.fkKeywordRolleKontakt'
ALTER TABLE dbo.tlkpRolleKontakt
DROP COLUMN fkKeywordRolleKontakt
That's it :)
Did you try first:
ALTER TABLE <tablename> DROP CONSTRAINT defEmptyString;
?
drop the constraint which is dependent on that column with
ALTER TABLE TableName DROP CONSTRAINT dependent_constraint
Then Drop Column:
ALTER TABLE TABLE_NAME DROP COLUMN COLUMN_NAME
dependent_constraint : this constraint is shown in the error when we try to delete dependent column.
Example: trying to drop some column IsDeleted2
Error
The object 'DF__Employees__IsDel__15502E78' is dependent on column
'IsDeleted2'.
ALTER TABLE DROP COLUMN IsDeleted2 failed because one or more objects
access this column.
Error clearly states that we need to delete DF__Employees__IsDel__15502E78 constraint
ALTER TABLE Employess
DROP CONSTRAINT DF__Employees__IsDel__15502E78;
Drop Column: ALTER TABLE Employess DROP COLUMN IsDelted2
I could solve the problem now. I'm sorry, I did not copy the full error message, which was:
Msg 5074, Level 16, State 1, Line 1
The object 'defEmptyString' is dependent on column 'fkKeywordRolleKontakt'.
Msg 5074, Level 16, State 1, Line 1 The object
'FK_tlkpRolleKontakt_tlkpKeyword' is dependent on column
'fkKeywordRolleKontakt'. Msg 4922, Level 16, State 9, Line 1 ALTER TABLE DROP COLUMN fkKeywordRolleKontakt failed because one or
more objects access this column.
I could generate a script to drop the column by right-clicking on the column entry (dbo.tlkpRolleKontakt > Columns > fkKeywordRolleKontakt) (in MSSQL Server Manager), selecting Modify and deleting the column. Then Table Designer > Generate Change Script generated the necessary commands:
ALTER TABLE dbo.tlkpRolleKontakt
DROP CONSTRAINT FK_tlkpRolleKontakt_tlkpKeyword
EXECUTE sp_unbindefault N'dbo.tlkpRolleKontakt.fkKeywordRolleKontakt'
ALTER TABLE dbo.tlkpRolleKontakt
DROP COLUMN fkKeywordRolleKontakt
use this script to cancel the checking of constraint :
ALTER TABLE #tablename NOCHECK CONSTRAINT #constraintname
I ran into a simpler solution.
DELETE the data of that column.
Once the column has no value inside it do -
ALTER TABLE <table_name> DROP COLUMN <column_name>
This way the column is easily dropped.
P.S - This is a headache if you have like extreme amounts of data in the column.