Showing posts with label create. Show all posts
Showing posts with label create. Show all posts

Sunday, March 25, 2012

Collation Issue

In SQL Server 2005 with SQL_Latin1_General_CP1_CS_AS collation, if you create a table:

create table TEST_TABLE

(
ID NVARCHAR(9) NOT NULL,
DESCRIPTION NVARCHAR(30),
);

Run the following insert statement from our Unicode application through ODBC on a system with U. S. English as the default code page:

insert into TEST_TABLE (ID, DESCRIPTION) values ('中文', '123');

The row was added properly. Now if you select * from TEST_TABLE, the row is properly returned to our app with the Chinese characters intact.

However, if you put the Chinese characters as part of the where clause:

select * from TEST_TABLE where ID = '中文';

It would not return anything.

On the other hand, if this is done on Oracle 10g or Access database, the row is returned properly with the Chinese characters intact.

So far we found two ways to fix it, but both involve tremendous risk for us:

  1. Change the database collation to Chinese.However, this defeats the purpose of using Unicode as only one language (Chinese in this case) can be used with such configuration.In case we need to mix Chinese, Japanese and Korean, such configuration will not work.

  1. Prefix the Unicode strings with N-prefix:


select * from TEST_TABLE where ID = N'中文'

This works perfectly but we have a few hundreds of such strings in our code and would be a nightmare to convert each one of them.

Is there any other solution for SQL Server 2005?

I am not sure that you will be able to accomplish what you are trying. You can change the collation at the column level, rather than the database level if you need to....or, you can add the COLLATE clause to each of your queries. Otherwise, I don't think that there is a really good way to get around it.

Tim

|||

Unfortunately, there are a few things with SQL Server that could use improvement.

UniCode strings 'should' always be prefixed with [ N ] -and especially if the sting contains UniCode characters not supported in the current codepage.

As the saying goes, "I feel your pain". You have have a bit of work to find the 'few hundreds of such strings' and makes the necessary changes.

sqlsql

Thursday, March 22, 2012

Collation conflict

I have 2 servers, both of them have the same collation.
Then I create temp table on 1st server:
create table #tmpNovi (country char(3) COLLATE database_default ,datum
datetime)
Then fill the table.
Then I join this table to second server:
select s.* FROM
[SERVER2].[DW_Temp].[dbo].[t_stanje_cube] s INNER JOIN #tmpNovi n
ON s.RCO=n.country
and I get an error message:
Cannot resolve collation conflict for equal to operation.
Why? Both servers have the same collation, also temp table country field has
defined COLLATE database_default and still an error?
Thank you,
SimonRun below statement on both servers and post back the results:
SELECT DATABASEPROPERTYEX('pubs', 'Collation')
Substitute pubs with DW_Temp when you execute it on SERVER2 and with the dat
abase name from where
you create the temp table on the other server.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"simon" <simon.zupan@.stud-moderna.si> wrote in message
news:%23P5qSQeNFHA.2520@.tk2msftngp13.phx.gbl...
>I have 2 servers, both of them have the same collation.
> Then I create temp table on 1st server:
> create table #tmpNovi (country char(3) COLLATE database_default ,datum dat
etime)
> Then fill the table.
> Then I join this table to second server:
> select s.* FROM
> [SERVER2].[DW_Temp].[dbo].[t_stanje_cube] s INNER JOIN #tmpNovi n
> ON s.RCO=n.country
> and I get an error message:
> Cannot resolve collation conflict for equal to operation.
> Why? Both servers have the same collation, also temp table country field h
as defined COLLATE
> database_default and still an error?
> Thank you,
> Simon
>|||Dear all,
As far as I know it's very simply: just for that is needed that both level o
f
COLLATION coinciding, i.e, level table, level database.
It's strange.
See you,
"simon" wrote:

> I have 2 servers, both of them have the same collation.
> Then I create temp table on 1st server:
> create table #tmpNovi (country char(3) COLLATE database_default ,datum
> datetime)
> Then fill the table.
> Then I join this table to second server:
> select s.* FROM
> [SERVER2].[DW_Temp].[dbo].[t_stanje_cube] s INNER JOIN #tmpNovi n
> ON s.RCO=n.country
> and I get an error message:
> Cannot resolve collation conflict for equal to operation.
> Why? Both servers have the same collation, also temp table country field h
as
> defined COLLATE database_default and still an error?
> Thank you,
> Simon
>
>|||Hi Tibor,
Great with DATABASEPROPERTYEX.I was wondering if it is possible to have
available a similar sentence but at table level?
thanx
"Tibor Karaszi" wrote:

> Run below statement on both servers and post back the results:
> SELECT DATABASEPROPERTYEX('pubs', 'Collation')
> Substitute pubs with DW_Temp when you execute it on SERVER2 and with the d
atabase name from where
> you create the temp table on the other server.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
> http://www.sqlug.se/
>
> "simon" <simon.zupan@.stud-moderna.si> wrote in message
> news:%23P5qSQeNFHA.2520@.tk2msftngp13.phx.gbl...
>
>|||Try sp_help.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"Enric" <Enric@.discussions.microsoft.com> wrote in message
news:3B49DD33-1160-4069-A161-7A5313738DBC@.microsoft.com...
> Hi Tibor,
> Great with DATABASEPROPERTYEX.I was wondering if it is possible to have
> available a similar sentence but at table level?
> thanx
> "Tibor Karaszi" wrote:
>

Collation and views

Suppose you have your databases's collation as X but the value of collation
on the varchar fields of some of your tables as Y.
Suppose you create a view like this:
SELECT 'CostantString1', 'CostantString2', Field1, Field2 FROM
Table_A
UNIONA ALL
SELECT VarcharField1, VarcharField2, Field3, Field4 FROM
Table_B
You've got an error of incompatble collation on the first two columns of the
view. I think because on the constant string values the db assign the
collation X while the corresponding varchar fields of Table_B have
collation Y.
Is there any solution to this problem?
Thank you all
Andreayes, there is: use COLLATE clause in the select statement.
dean
"Andrea Temporin" <NOSPAM_temporin@.encopro.it> wrote in message
news:%232K2hKyGFHA.3108@.tk2msftngp13.phx.gbl...
> Suppose you have your databases's collation as X but the value of
collation
> on the varchar fields of some of your tables as Y.
> Suppose you create a view like this:
> SELECT 'CostantString1', 'CostantString2', Field1, Field2 FROM
> Table_A
> UNIONA ALL
> SELECT VarcharField1, VarcharField2, Field3, Field4 FROM
> Table_B
> You've got an error of incompatble collation on the first two columns of
the
> view. I think because on the constant string values the db assign the
> collation X while the corresponding varchar fields of Table_B have
> collation Y.
> Is there any solution to this problem?
> Thank you all
> Andrea
>

Monday, March 19, 2012

Collate

Hi,
Could anyone tell me what does COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL/NULL do in the following code?
CREATE TABLE [TABLE1] (
[ProjectID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL )
Why do I need COLLATE? What does COLLATION mean in table creation?
Thanks a lot!
MikeThanks a lot!
RLoski wrote:
> Collate sets the order that items are compared with. It determines how an
> order by is handled. It also determines whether two items are the same or
> different. The collation you have there states that "APPLE" = "Apple" A
> different collation will make these different.
> This is one of the annoying quirks of the tool to create SQL. Since
> individual columns can have their own collation, the tool exports all of the
> collations even if the collation is the default for the database.
> Unless you have a good reason to use a specific collation, I would delete
> the whole collate clause.
> --
> Russel Loski, MCSD.Net
>
> "Michael" wrote:
> > Hi,
> >
> > Could anyone tell me what does COLLATE SQL_Latin1_General_CP1_CI_AS NOT
> > NULL/NULL do in the following code?
> >
> > CREATE TABLE [TABLE1] (
> > [ProjectID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
> > NULL )
> >
> > Why do I need COLLATE? What does COLLATION mean in table creation?
> >
> > Thanks a lot!
> > Mike
> >
> >|||RLoski,
While generating your script, use unicode option. Then it will not generate
the collate... statements. so you don't need to go and delete them manually.
Venkat
"RLoski" wrote:
> Collate sets the order that items are compared with. It determines how an
> order by is handled. It also determines whether two items are the same or
> different. The collation you have there states that "APPLE" = "Apple" A
> different collation will make these different.
> This is one of the annoying quirks of the tool to create SQL. Since
> individual columns can have their own collation, the tool exports all of the
> collations even if the collation is the default for the database.
> Unless you have a good reason to use a specific collation, I would delete
> the whole collate clause.
> --
> Russel Loski, MCSD.Net
>
> "Michael" wrote:
> > Hi,
> >
> > Could anyone tell me what does COLLATE SQL_Latin1_General_CP1_CI_AS NOT
> > NULL/NULL do in the following code?
> >
> > CREATE TABLE [TABLE1] (
> > [ProjectID] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
> > NULL )
> >
> > Why do I need COLLATE? What does COLLATION mean in table creation?
> >
> > Thanks a lot!
> > Mike
> >
> >

Collapsing/Expanding Group Data in Table and Matrix Data Regions

Hi,

Is it possible to create Expand/Collapse functionality for the grouped data in Table and Matrix data regions? Essentially, the idea is for the user to be able to see the group/subgroup data if she wishes to by clicking on (+/-) symbols, as is usually the case in Tree View style data grid control in web apps. Any ideas how to accomplish the same in reporting services?

Thanks.

Never mind... I found it in the Tutorials How-To topics under grouping data regions section.

Collapse All Groups

Does anyone know how to create a button or link that would collapse all open
groups? I'd like a link/button that would collapse all lower level items.
For example if your report looks like this:
Level 1
Level 2
Level 3
And the user has it drilleddown all the way, they could click the button and
it would collapse so it only showed Level1. Any ideas?
DerekUnfortunately, this feature is not currently supported. If the default
state of the report was only Level 1 shown, they could always refresh.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Derek Fisher" <DerekFisher@.discussions.microsoft.com> wrote in message
news:44918CD9-0D33-4F6B-B301-88C2CCCBB08C@.microsoft.com...
> Does anyone know how to create a button or link that would collapse all
> open
> groups? I'd like a link/button that would collapse all lower level items.
> For example if your report looks like this:
> Level 1
> Level 2
> Level 3
> And the user has it drilleddown all the way, they could click the button
> and
> it would collapse so it only showed Level1. Any ideas?
> Derek|||Thanks. I just wanted to see if there was some way to do this.
"Donovan Smith [MSFT]" wrote:
> Unfortunately, this feature is not currently supported. If the default
> state of the report was only Level 1 shown, they could always refresh.
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Derek Fisher" <DerekFisher@.discussions.microsoft.com> wrote in message
> news:44918CD9-0D33-4F6B-B301-88C2CCCBB08C@.microsoft.com...
> > Does anyone know how to create a button or link that would collapse all
> > open
> > groups? I'd like a link/button that would collapse all lower level items.
> > For example if your report looks like this:
> > Level 1
> > Level 2
> > Level 3
> > And the user has it drilleddown all the way, they could click the button
> > and
> > it would collapse so it only showed Level1. Any ideas?
> >
> > Derek
>
>

Sunday, March 11, 2012

Code suggestions for database searches

I have a database containing several tables with many different fields. I need to create an admin section that lets me search on one field or the combination of several. Does anyone have links to pages that offer a general overview for inhouse database search strategy and admin edits.

Thank you

>> I need to create an admin section that lets me search on one field or the combination of several.

Do you means within a given table or across all tables?

>> database search strategy and admin edits

If across all tables, what about validation? A generic edit solution would bypasss data validation checks - not a good idea.

|||I need it across several tables and I am experimenting with the Multi_View control because although it only displays one view at a time all controls are accessible because the Views do not function as seperate containers. So far it seems to be meeting the major requirements however the displays are a little hard to figure out.|||

Have you considered how to handle data validation?

|||

I am doing that using Validation controls on the database submission form and in the View Edit template. At least I expect Validation will work in the Views.

Thursday, March 8, 2012

Code for Scripts

I'm looking for code that will create a script of a stored procedure vs.
going through the gui. Can anyone help?
See the below link:
http://www.karaszi.com/sqlserver/inf...ate_script.asp
Thanks
Hari
SQL Server MVP
"Chad" <Chad@.discussions.microsoft.com> wrote in message
news:69FCF02E-E868-4A1C-AB28-36562C8B5571@.microsoft.com...
> I'm looking for code that will create a script of a stored procedure vs.
> going through the gui. Can anyone help?

code creating a flat file destination

I'm looking for a manner to create by code a flat file connection manager and a flat file destination.GreetsTry the last post in this thread -http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=359347&SiteID=1|||Thanks!

Wednesday, March 7, 2012

Code a function to return a dataset in which there are two tables and relationship

I used a function to create dataset as below:

PublicFunction GetSQLDataSet(ByVal SQLAsString)As DataSet

.....

MyConnection =

New SqlConnection(MyConnectionString)

MyCommand =

New SqlCommand(SQL, MyConnection)

MyDataSet =

New DataSet

MySQLDataAdapter =

New SqlDataAdapter(MyCommand)

MySQLDataAdapter.Fill(MyDataSet)

.....

End function

It works fine.

How to code a function to return a dataset in which there are two tables and relationship?

You can use a SqlCommand which returns 2 tables--that can be a stored procedure which returns 2 tables, or a batch contains 2 SELECT commands seperated by ';' (e.g. "select * from t1; select * from t2). Then when you use the SqlDataAdapter to fill the DataSet, the DataSet will contain 2 tables. Then you can add relationships between the 2 tables as you like, you can refer to:

http://msdn2.microsoft.com/en-us/library/ay82azad.aspx

Code - Anyone seen a replication Progress Indicator?

My app is done in c# and controls merge replication programatically.
Does anyone have any info on how to create a progress indicator for
replication?
I know that for the upcoming sql mobile, there are plans to include one
in the data.sqlserverce namespace. But I have to program one for
windows mobile as well as xp.
thoughts?
thanks,
JJ
What about the status event. This gives some indication of progress.
Hilary Cotter
Looking for a SQL Server replication book?
http://www.nwsu.com/0974973602.html
Looking for a FAQ on Indexing Services/SQL FTS
http://www.indexserverfaq.com
"JJ" <joe.jabour@.gmail.com> wrote in message
news:1118151716.660527.200700@.o13g2000cwo.googlegr oups.com...
> My app is done in c# and controls merge replication programatically.
> Does anyone have any info on how to create a progress indicator for
> replication?
> I know that for the upcoming sql mobile, there are plans to include one
> in the data.sqlserverce namespace. But I have to program one for
> windows mobile as well as xp.
> thoughts?
> thanks,
> JJ
>

Saturday, February 25, 2012

cmdsql - Create a text file without Informational Messages

Hello all

I have a sql file that I want execute by using the cmdsql command line. But when I create a text file I receive two Informational Messages:

1."Changed database context to 'DataBaseName'."

2.(2 row(s) affected)

How can I ignore these messages in my text file? there is a parametter or something elese to configure to avoir these Informational Messages?

Sorry is not cmdsql is Sqlcmd :)

CmdExec Job Step in Sql Server2000

Thanks for the invitation to post a question, so I will post one.

I need to create a job step that uses cmdExec.

This is the command line I entering:
D:\odbc\TimeClockUpdates\bin\Release\TimeKeepingNo nLogouts.exe

When I run this job the job fails. When I look at the job history, the only information I get is the date and time, user that ran the job and the fact that it failed. I haven't been able to get any CmdExec job to run at all. Can anyone tell me what I'm doing wrong?

Facts.
1. This exact same command is used by my network administrator using windows scheduler on the server. The only reason he wants me to create an sql server job is because it's mostly sql functions.
2. I know the Sql Server agent is running, because I have other jobs that are run.
3. I have verified that I have permission to run the file because I can go to the actual directory and run the exe.
4. Do I need to enclose my command in quotes i.e. D:\odbc\TimeClockUpdates\bin\Release\TimeKeepingN onLogouts.exe
5. the path of the file I need to run is the path on the server and not the path on my local machine.

If you need any other information, please let me know
Thanks for you help
GEMyou should post the code.

cmdexec requires that the security account executing job have sysadmin permissions.|||I wish I knew what code you mean me to post

This is a job I created using enterprise manager to create the job.
1. I entered the Job Name: UpdateEmployeeLogins
2. Job type: Operation System Command (CmdExec)
3. Command: D:\odbc\TimeClockUpdates\bin\Release\TimeKeepingNo nLogouts.exe

I did all this through Enterprise Manager. What code do you want me to post?

Thanks
GEM|||change the command type to t-sql and try this...

EXEC xp_cmdshell 'D:\odbc\TimeClockUpdates\bin\Release\TimeKeepingN o nLogouts.exe'|||I did as you suggested and but the same result. I then ran that command line with query analyzer and got an "Access Denied" Error so that means I must have a problem somewhere with permissions. This doesn't make a whole lot of sense since I can the exe when clicking on it. I will have to get with out network administrator who's not available right now.

Your help was excellent, I hope you'll be around later to help me with this if I need it.

Thanks
GEM|||see my 1st post.|||This is a job I created using enterprise manager to create the job.
1. I entered the Job Name: UpdateEmployeeLogins
2. Job type: Operation System Command (CmdExec)
3. Command: D:\odbc\TimeClockUpdates\bin\Release\TimeKeepingNo nLogouts.exe

This method should work. It should not be necessary to use xp_cmdshell in your job.
As Thrassy stated, this is likely due to a permissions issue regarding the account that the SQL Agent service is running under.|||As everyone else said, make sure that the account executing the command under the SQL service privileges has the appropriate access to the executable. I bet if you look under NTFS security on the target .exe you'll find the problem.

Clustrer DB engine and SAS?

Is it possible to create a SQL Server 2005 cluster and run SAS 2005 clustered on the same servers?

In particular I want to run a cluster of 6 servers as follows:-

* 3 active servers running mulitple instances of SQL Server 2005
* 1 active server running Reporting Servies and Analysis Services
* 2 passive servers for failover

Is this feasible and pratical?

Thanks
Ken
Yes, it is. SSAS will install into a cluster just like the Database Engine will. You generally don't cluster Reporting Services though since it simply relies on a database which would already be covered by clustering the SQL Server instance that is hosting the repository database.

Sunday, February 19, 2012

Clustering Nodes

Can I create a 2-node cluster using servers with different CPU configs? I have a dual CPU in one node and a quad cpu in another that I want to be able to cluster SQL 2000.
TIA,
Ken
Possible, Yes.
Recommended, No.
FYI, you can't just pick two machines at random and create a cluster.
First, the machines must be on the Cluster HCL (Hardware Compatability
List). Second, they must be installed and configured by a certified cluster
vendor. Otherwise, you may not be able to obtain support for your cluster.
(Or at least the support stops at 'You need to be on a certified cluster'.)
If all you are interested in is a cluster for testing and training, then go
right ahead and grab whatever is lying around. If you want a cluster to be
the centerpiece of a High-Availability database solution, then you need to
go with a certified install.
Geoff N. Hiten
Microsoft SQL Server MVP
Senior Database Administrator
Careerbuilder.com
I support the Professional Association for SQL Server
www.sqlpass.org
"Ken Krause" <anonymous@.discussions.microsoft.com> wrote in message
news:D0EA9DE7-3445-45A7-8F4A-EB397C94CBFE@.microsoft.com...
> Can I create a 2-node cluster using servers with different CPU configs? I
have a dual CPU in one node and a quad cpu in another that I want to be able
to cluster SQL 2000.
> TIA,
> Ken
|||Thanks for the response. I have a clustered pair of nodes with all hardware on the HCL and have been running without any clustering problems whatsoever. However, the database at the center of this web-based app is running into cpu bettlenecks which causes
extremely poor performance. This has been building for a few months now. I want to go to a quad cpu to eliminate this bottleneck, but can only get the funds for one server at a time. I need the performance right now, but want to keep the clustering for a
vailability.
|||Here's an article which describes the tolerable difference between your
cluster nodes and still maintain support for your cluster:
http://support.microsoft.com/default...b;en-us;814607
It'll work and it's supported, though certainly not recommended.
Regards,
John
"kmkrause2" <anonymous@.discussions.microsoft.com> wrote in message
news:055EEAD5-EB16-438B-B9AC-045F2EC9415C@.microsoft.com...
> Thanks for the response. I have a clustered pair of nodes with all
hardware on the HCL and have been running without any clustering problems
whatsoever. However, the database at the center of this web-based app is
running into cpu bettlenecks which causes extremely poor performance. This
has been building for a few months now. I want to go to a quad cpu to
eliminate this bottleneck, but can only get the funds for one server at a
time. I need the performance right now, but want to keep the clustering for
availability.
|||Thanks for the link, John. Now if only the server would get here. It seems DHL has lost it. It shipped from Vegas and hasn't been documented since it left there 2 days ago. Probably has been stolen, or maybe I've been watching too much Soprano's.

Tuesday, February 14, 2012

Clustered Primary Key

Hello!
How can I create a clustered primary key?
This alter table statement get the following error:
ALTER TABLE test ADD CONSTRAINT
PK_Table_1 Primary Key CLUSTERED
(
[Field 1],
[Field 2]
)
The constraint specified is not valid.

Thank you
SaschaThe CLUSTERED keyword is not supported by SQL Compact Edition. If you drop it, the statement should run OK.

Clustered Indexes

I have a DB which has tables for each month with about 9 million rows each.
Now after that we create a clustered index on the table with specific
required columns. The issue is that the primary datafile doesn't grow much
every month but the secondary file, which has only indexes is huge abt 70
GB. Every month as the previous month's data is not needed on a regular
basis, I tried dropping the clustered index in a hope that this might save
some space but of no use.
Any advice?
When you create a clustered index, the leaf pages are the data pages. Thus,
if you create a clustered index and specify the filegroup, the data pages
will go into that filegroup.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"Renu Doda" <renu.doda@.newsgroup.nospam> wrote in message
news:%23kQjWN3oFHA.2976@.TK2MSFTNGP12.phx.gbl...
I have a DB which has tables for each month with about 9 million rows each.
Now after that we create a clustered index on the table with specific
required columns. The issue is that the primary datafile doesn't grow much
every month but the secondary file, which has only indexes is huge abt 70
GB. Every month as the previous month's data is not needed on a regular
basis, I tried dropping the clustered index in a hope that this might save
some space but of no use.
Any advice?
|||Yeah, the fact of the matter is you have about 70G of data (ie. not
indexes - as Tom says a clustered index IS the data itself) and it has
to go somewhere.
You may be able to squish it a little by rebuilding the clustered
index(es) in question and specifying a fill factor of 100% to ensure
you're not leaving any empty space on each data page (ie. leaf node of
the clustered index). That will cram as much data as possible onto each
data page, which may mean your 70G may come down a little (if there was
empty space already, for example if the clustered indexes were built
with a fill factor less than 100%) but it may not.
A downside to 100% fill factors though is if there are changes to the
clustered keys or inserts, then you'll get quite a lot of page splits
because there's no free space on each data page to put the new/changed
key (so SQL Server has to split an existing page (known as a page split)
onto 2 new pages in the index, each being 50% full, so it can fit the
new/changed data in the correct location in the index), which will mean
increased I/O against those clustered indexes. But I'm assuming data
from past months won't change much so presumedly there won't be many
changes to make to the clustered keys.
*mike hodgson*
blog: http://sqlnerd.blogspot.com
Tom Moreau wrote:

>When you create a clustered index, the leaf pages are the data pages. Thus,
>if you create a clustered index and specify the filegroup, the data pages
>will go into that filegroup.
>
>
|||In addition to the other replies: if you drop the clustered index, the
data will remain in the filegroup of the clustered index. To move the
data to another filegroup you would have to recreate the index on the
desired filegroup (easiest with CREATE ... CLUSTERED INDEX ... WITH
DROP_EXISTING).
Gert-Jan
Renu Doda wrote:
> I have a DB which has tables for each month with about 9 million rows each.
> Now after that we create a clustered index on the table with specific
> required columns. The issue is that the primary datafile doesn't grow much
> every month but the secondary file, which has only indexes is huge abt 70
> GB. Every month as the previous month's data is not needed on a regular
> basis, I tried dropping the clustered index in a hope that this might save
> some space but of no use.
> Any advice?

Clustered Indexes

I have a DB which has tables for each month with about 9 million rows each.
Now after that we create a clustered index on the table with specific
required columns. The issue is that the primary datafile doesn't grow much
every month but the secondary file, which has only indexes is huge abt 70
GB. Every month as the previous month's data is not needed on a regular
basis, I tried dropping the clustered index in a hope that this might save
some space but of no use.
Any advice?When you create a clustered index, the leaf pages are the data pages. Thus,
if you create a clustered index and specify the filegroup, the data pages
will go into that filegroup.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Renu Doda" <renu.doda@.newsgroup.nospam> wrote in message
news:%23kQjWN3oFHA.2976@.TK2MSFTNGP12.phx.gbl...
I have a DB which has tables for each month with about 9 million rows each.
Now after that we create a clustered index on the table with specific
required columns. The issue is that the primary datafile doesn't grow much
every month but the secondary file, which has only indexes is huge abt 70
GB. Every month as the previous month's data is not needed on a regular
basis, I tried dropping the clustered index in a hope that this might save
some space but of no use.
Any advice?|||Yeah, the fact of the matter is you have about 70G of data (ie. not
indexes - as Tom says a clustered index IS the data itself) and it has
to go somewhere.
You may be able to squish it a little by rebuilding the clustered
index(es) in question and specifying a fill factor of 100% to ensure
you're not leaving any empty space on each data page (ie. leaf node of
the clustered index). That will cram as much data as possible onto each
data page, which may mean your 70G may come down a little (if there was
empty space already, for example if the clustered indexes were built
with a fill factor less than 100%) but it may not.
A downside to 100% fill factors though is if there are changes to the
clustered keys or inserts, then you'll get quite a lot of page splits
because there's no free space on each data page to put the new/changed
key (so SQL Server has to split an existing page (known as a page split)
onto 2 new pages in the index, each being 50% full, so it can fit the
new/changed data in the correct location in the index), which will mean
increased I/O against those clustered indexes. But I'm assuming data
from past months won't change much so presumedly there won't be many
changes to make to the clustered keys.
*mike hodgson*
blog: http://sqlnerd.blogspot.com
Tom Moreau wrote:

>When you create a clustered index, the leaf pages are the data pages. Thus
,
>if you create a clustered index and specify the filegroup, the data pages
>will go into that filegroup.
>
>|||In addition to the other replies: if you drop the clustered index, the
data will remain in the filegroup of the clustered index. To move the
data to another filegroup you would have to recreate the index on the
desired filegroup (easiest with CREATE ... CLUSTERED INDEX ... WITH
DROP_EXISTING).
Gert-Jan
Renu Doda wrote:
> I have a DB which has tables for each month with about 9 million rows each
.
> Now after that we create a clustered index on the table with specific
> required columns. The issue is that the primary datafile doesn't grow much
> every month but the secondary file, which has only indexes is huge abt 70
> GB. Every month as the previous month's data is not needed on a regular
> basis, I tried dropping the clustered index in a hope that this might save
> some space but of no use.
> Any advice?

Clustered Indexes

I have a DB which has tables for each month with about 9 million rows each.
Now after that we create a clustered index on the table with specific
required columns. The issue is that the primary datafile doesn't grow much
every month but the secondary file, which has only indexes is huge abt 70
GB. Every month as the previous month's data is not needed on a regular
basis, I tried dropping the clustered index in a hope that this might save
some space but of no use.
Any advice?When you create a clustered index, the leaf pages are the data pages. Thus,
if you create a clustered index and specify the filegroup, the data pages
will go into that filegroup.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"Renu Doda" <renu.doda@.newsgroup.nospam> wrote in message
news:%23kQjWN3oFHA.2976@.TK2MSFTNGP12.phx.gbl...
I have a DB which has tables for each month with about 9 million rows each.
Now after that we create a clustered index on the table with specific
required columns. The issue is that the primary datafile doesn't grow much
every month but the secondary file, which has only indexes is huge abt 70
GB. Every month as the previous month's data is not needed on a regular
basis, I tried dropping the clustered index in a hope that this might save
some space but of no use.
Any advice?|||This is a multi-part message in MIME format.
--060606090504010006000906
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: 7bit
Yeah, the fact of the matter is you have about 70G of data (ie. not
indexes - as Tom says a clustered index IS the data itself) and it has
to go somewhere.
You may be able to squish it a little by rebuilding the clustered
index(es) in question and specifying a fill factor of 100% to ensure
you're not leaving any empty space on each data page (ie. leaf node of
the clustered index). That will cram as much data as possible onto each
data page, which may mean your 70G may come down a little (if there was
empty space already, for example if the clustered indexes were built
with a fill factor less than 100%) but it may not.
A downside to 100% fill factors though is if there are changes to the
clustered keys or inserts, then you'll get quite a lot of page splits
because there's no free space on each data page to put the new/changed
key (so SQL Server has to split an existing page (known as a page split)
onto 2 new pages in the index, each being 50% full, so it can fit the
new/changed data in the correct location in the index), which will mean
increased I/O against those clustered indexes. But I'm assuming data
from past months won't change much so presumedly there won't be many
changes to make to the clustered keys.
--
*mike hodgson*
blog: http://sqlnerd.blogspot.com
Tom Moreau wrote:
>When you create a clustered index, the leaf pages are the data pages. Thus,
>if you create a clustered index and specify the filegroup, the data pages
>will go into that filegroup.
>
>
--060606090504010006000906
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<tt>Yeah, the fact of the matter is you have about 70G of data (ie. not
indexes - as Tom says a clustered index IS the data itself) and it has
to go somewhere.<br>
<br>
You may be able to squish it a little by rebuilding the clustered
index(es) in question and specifying a fill factor of 100% to ensure
you're not leaving any empty space on each data page (ie. leaf node of
the clustered index). That will cram as much data as possible onto
each data page, which may mean your 70G may come down a little (if
there was empty space already, for example if the clustered indexes
were built with a fill factor less than 100%) but it may not.<br>
<br>
A downside to 100% fill factors though is if there are changes to the
clustered keys or inserts, then you'll get quite a lot of page splits
because there's no free space on each data page to put the new/changed
key (so SQL Server has to split an existing page (known as a page
split) onto 2 new pages in the index, each being 50% full, so it can
fit the new/changed data in the correct location in the index), which
will mean increased I/O against those clustered indexes. But I'm
assuming data from past months won't change much so presumedly there
won't be many changes to make to the clustered keys.</tt><br>
<div class="moz-signature">
<title></title>
<meta http-equiv="Content-Type" content="text/html; ">
<p><span lang="en-au"><font face="Tahoma" size="2">--<br>
</font></span> <b><span lang="en-au"><font face="Tahoma" size="2">mike
hodgson</font></span></b><span lang="en-au"><br>
<font face="Tahoma" size="2">blog:</font><font face="Tahoma" size="2"> <a
href="http://links.10026.com/?link=http://sqlnerd.blogspot.com</a></font></span>">http://sqlnerd.blogspot.com">http://sqlnerd.blogspot.com</a></font></span>
</p>
</div>
<br>
<br>
Tom Moreau wrote:
<blockquote cite="miduJA4xn3oFHA.3988@.TK2MSFTNGP10.phx.gbl" type="cite">
<pre wrap="">When you create a clustered index, the leaf pages are the data pages. Thus,
if you create a clustered index and specify the filegroup, the data pages
will go into that filegroup.
</pre>
</blockquote>
</body>
</html>
--060606090504010006000906--|||In addition to the other replies: if you drop the clustered index, the
data will remain in the filegroup of the clustered index. To move the
data to another filegroup you would have to recreate the index on the
desired filegroup (easiest with CREATE ... CLUSTERED INDEX ... WITH
DROP_EXISTING).
Gert-Jan
Renu Doda wrote:
> I have a DB which has tables for each month with about 9 million rows each.
> Now after that we create a clustered index on the table with specific
> required columns. The issue is that the primary datafile doesn't grow much
> every month but the secondary file, which has only indexes is huge abt 70
> GB. Every month as the previous month's data is not needed on a regular
> basis, I tried dropping the clustered index in a hope that this might save
> some space but of no use.
> Any advice?

Sunday, February 12, 2012

Clustered index on Identity field

Hi All,
I have heard that if you create a clustered index on identity column(PK
also) it would decrease the page splits. But how?
Thanks,
PradeepIt will eliminate page splits on inserts since all new rows get appended to
the end of the current page. It does not stop pagespilts due to updates on
existing rows on columns with variable lengths. But in any case that should
not be your sole motivation for where you place the Clustered Index. You can
also avoid or minimize page splits with a proper fill factor.
Andrew J. Kelly SQL MVP
"Pradeep Kutty" <pradeepk@.healthasyst.com> wrote in message
news:eW2tO%23HtFHA.2656@.TK2MSFTNGP10.phx.gbl...
> Hi All,
> I have heard that if you create a clustered index on identity column(PK
> also) it would decrease the page splits. But how?
> Thanks,
> Pradeep
>