Hi everyone, When we create a clustered index firstly, and then is it advantageous to create another index which is nonclustered ?? In my opinion, yes it is. Because, since we use clustered index first, our rows are sorted and so while using nonclustered index on this data file, finding adress of the record on this sorted data is really easier than finding adress of the record on unsorted data, is not it ??
Table A (15 field, 4 fields indexed and Primary Key) approximate rows: 50.000 60.000
Table B (18 field, 6 fields indexed and Primary Key) approximate rows: 350.000 500.000
Table C (16 filed, 9 fields indexed and Primary Key) approximate rows: 500.000 1.000.000
Structure is something like this: A (master) --> B (detail) ---> C (sub detail)
On each 3 table is added new record, in table C the record is added after a search in table B. My question is: Which is the best method? CLUSTERED INDEX or NONCLUSTERED INDEX
i only know you use clustered when you have million of records. So once the table has been indexed, query statement is able to retrieve the recordset faster.
Hi guys. I have a table named [Check] and need to create an index for CVNumber field. The table has no primary key for the meantime. I tried this script but error occured.
BEGIN TRANSACTION SET QUOTED_IDENTIFIER ON GO SET TRANSACTION ISOLATION LEVEL SERIALIZABLE GO COMMIT BEGIN TRANSACTION CREATE NONCLUSTERED INDEX IX_Check_1 ON dbo.[Check] ( CVNumber ) ON [PRIMARY] GO COMMIT
Error message:
Server: Msg 3023, Level 16, State 2, Line 3 Backup, CHECKALLOC, bulk copy, SELECT INTO, and file manipulation (such as CREATE FILE) operations on a database must be serialized. Reissue the statement after the current backup, CHECKALLOC, or file manipulation operation is completed. Server: Msg 3902, Level 16, State 1, Line 1 The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
Is it because I used the table name Check which is a reserved word for SQL? But I included [ ].
Hi everyone, I have some problems on composite nonclustered indexes. I could not exatly understand their logic. In my opininon, suppose that we have a table called Order and we create a composite nonclustered index on this table for OrderID column and OrderDate column. So I am using this query;
SELECT * FROM Order WHERE OrderID > 12 ORDER BY OrderDate So in here, I think our first research is based on OrderID and ten after ordering our data pointer according to the OrderID and then our index is converted to an index which is based on OrderDate while performing ordering. So is this correct ?? Would you please explain this ?
When a nonunique nonclustered index is built on top of a clusteredindex, is it guaranteed that the bookmark in the nonclustered indexwill be kept in the same order as the clustered index?Here's an example to demonstrate my question:CREATE TABLE indextest (col1 int NOT NULL,col2 int NOT NULL,col3int,col4 int)ALTER TABLE indextest ADD PRIMARY KEY CLUSTERED (col1,col2)CREATE INDEX ix_indextest ON indextest (col1,col3)GOINSERT indextest VALUES (1,2,1,1)INSERT indextest VALUES (1,3,2,1)INSERT indextest VALUES (1,4,2,1)INSERT indextest VALUES (2,1,1,1)INSERT indextest VALUES (1,1,1,1)SELECT col1,col2 FROM indextest WHERE col1=1 AND col3=1DROP TABLE indextestThe select statement above is covered by the nonclustered index, sothat index is used. However, the nonclustered index is defined only toensure the ordering of col1 and col3 within the index; col1 and col2follow within the index as the bookmark to the clustered index. When Irun this query, my desired result is to have the records appear in theorder supported by the clustered index:1,11,2As it happens, the result I got was indeed in that order, but I don'tknow if it was mere coincidence, or if the bookmark in the nonclusteredindex is maintained in the same order as the clustered index. If Iwant to ensure the above order, is it sufficient to have thenonclustered index defined as above, or do I need to define it as:create index ix_indextest on indextest (col1,col3,col2)just to be sure that the results are returned in ascending order forcol1,col2? If the two-column index is sufficient, is it guaranteed tostill be sufficient in SQL2005 and future versions of SQL Server, or amI better off adding the third column just to be safe?Thank you,--Dennis Culley
I have table which having clustered index based on column (A,B,C,D,E,F).Now my query based on B,D,F.Β e.g: where b='Test1' and D='test2' and F='test3' Now Execution plan ask to create non clustered index with (B,D,F) column.is it make any sense to create non clustered index where clustered already available.
I have a table called "Jobs" on my SQL server. I have an access front end which connects to this as well as some access backend tables. We have 30+ users on the system. There are 1000s of records in this "jobs" table.
For some reason, at certain points of the day all users are stopped from updating a group of records. No-one can update values in a clump of records. It is usually 10-20 records that are numerically together. When i kick everyone off the system, and log back those particular records seem to be unlocked.
I can rule out permissions on the Jobs table. i am failry certain they have been set correctly.
To me it sounds like Page locking. Now i am new to SQL server. I am inheriting a recently created sql system.
But i notice there are multiple indexes formed on this JOBS table. I looked at one in particular. It is a "ClientName" field.. I noticed under this index > options...it says "Use Page locks when accessing the index".
Am i interpreting this right... But anyone searching under this field, will page lock on that table. And...if my memory serves me right, "page locking" locks a group of all the nearest records? Is this correct?
Does this sound like where my system is going wrong?
I know the shortcut to 'defragging' the database to eliminate and reclaim 'whitespace' in data and index pages is to setup a maintenance plan. This doesn't work for me for two reasons: 1. I like to know how things work. 2. I can not create maintenance plans with my hosted provider. I use the following T-SQL to rebuild all indexes on all tables:
But, does that not only address indexes? What about getting whitepace back from data in tables themselves? Am I over-thinking this? When you're paying for SQL by the MB and generate a lot of data (with a fair amount of churn) you want to keep it optimized and efficient, right?
I've just found a blocking lock occuring in a SQL Server.[color=blue]>From the waitresource, I found that the blocker has the following[/color]information:wait_info: PAGEIOLATCH_EXwait_resource: 14:1:564312And the blockee has the following information:wait_info: LCK_M_Swait_resource: KEY: 14:405576483:2 (7501a5aa8355)The problem is that I do not know which object is the blocker holding,for I understand that for a PAGE lock, it is in the format ofdatabase_id:file_id:page_idI know the db_id, the file_id but don't know how to map the page_id(564312) to a table/index in the database.Can somebody shed some lights on this? thks a lot.
Hello,I not exactly sure how to determine the table when given the followinginformation:--Could not find the index for RID '999999' in index page('1:99999999'), index id ), database (whatever).--Can you someone tell how I use the system tables to determine whattable this index corresponds to? I'm assuming I used sysindexes andsysobjects somehow.Thanks in advance,JGB_DBA
I have a page that has a drop down control that is used to control the items in a FormView. The drop down is bound to one SQLDatasource while the FormView is bound to another SQLDataSource. I've got everything working great. Selecting an item in the drop down reveals the details in the form view. the Form can be opened for editing and deleting. I even have the Insert working. But there lies my problem. Once the Insert is executed I'd like to take the Index value of the recently submitted item and set it to the SelectedIndex of my dropdown. Here is the code for each of the SQL events Sub FormViewUpdated(ByVal sender As Object, ByVal e As FormViewUpdatedEventArgs) Handles FormView1.ItemUpdated confirmation.Visible = True confirmation.Text = "<img src=""../img/smiley36.gif""> Your record has been updated."
Dim index As Integer = Me.DropDownList1.SelectedIndex DropDownList1.DataBind() Me.DropDownList1.SelectedIndex = index End Sub
Sub FormViewDeleted(ByVal sender As Object, ByVal e As FormViewDeletedEventArgs) Handles FormView1.ItemDeleted confirmation.Visible = True confirmation.Text = "<img src=""../img/smiley36.gif""> Your record has been deleted."
DropDownList1.DataBind() FormView1.ChangeMode(FormViewMode.ReadOnly) End Sub
Sub FormViewInserted(ByVal sender As Object, ByVal e As FormViewInsertedEventArgs) Handles FormView1.ItemInserted confirmation.Visible = True confirmation.Text = "<img src=""../img/smiley36.gif""> Your record has been inserted." DropDownList1.DataBind() End Sub I would like to do something similar to the Updated event in the Inserted sub. Notice I have a Me.DropDownList.SelectedIndex bit...I'd like to be able to set a variable to the new ID and then set the Me.DropDownList.SelectedIndex to that variable. My stored proc for the Insert reads like ALTER PROCEDURE dbo.usp_INSERTHelp_Faq ( @FAQQuestion varchar(500), @FAQText ntext, @FAQIndex varchar(500), @ModifiedBy int, @Help_FAQID int OUTPUT ) AS INSERT INTO Help_FAQ (FAQQuestion, FAQText, FAQIndex,ModifiedBy, Views) VALUES (@FAQQuestion,@FAQText,@FAQIndex,@ModifiedBy,0)
SELECT @Help_FaqID = @@Identity RETURN So, the Stored Proc is set up to return the latest ID. Also, my SQLDataSource for the FormView has an InsertParameter: <asp:Parameter Direction="Output" Name="Help_FAQID" Type="Int32" />
Any thoughts on how to close the loop here? How do I get my hands on the new Help_FAQID?
Table A 5.6GB 80 million rows Initial Page Space Used = 85.7% (sys.dm_db_index_physical_stats - avg_page_space_used_in_percent)
Index and data size are almost unchanged after an ONLINE rebuild of the clustered index. Page count actually goes up by 800. No fill factor or pad index settings. Page space used = 99.2%
During an OFFLINE rebuild the page count drops by ~20%. Page space used = 99.8%.
How can the pages be 99.2% used yet the number of pages hasn't gone done from the ONLINE rebuild?
I'm getting the feeling a shortcut was taken somewhere. Does an ONLINE rebuild only reorganize leaf level index pages but not any of the upper levels? Essentially it puts the pages in order but doesn't do any structure consolidation like OFFLINE?
It would seem that you're missing out on some of the benefits of defragmenting if your data is still spread across more pages and you don't get as many rows per read or it takes more reads to go down your tree to get to your data.
i have one col in a nonclusted index which is bigint 8 bytes follwoing result shows min_record_size_in_bytes and max_record_size_in_bytes is 20 that is 12+8 page size is 8 kB. does that mean a record will use 20 bytes in a page or it will only use the space equalent to data stored in the col.what i have seen is page count is same weather i put some data in the col or null
We noticed a deadlock 3-4 weeks ago on a table (table1) and deadlock graph was captured.
When I am analyzing the deadlock graph, page number using DBCC PAGE, I am getting the object id for a different table (table2). But deadlock graph shows the name of the object as table1.
Is it possible that subsequent defragmentation of indexes would have caused the respective page id to got re-allocated to a different table? I checked the deadlock graph lately only after 3-4 weeks.
Table has a 4 part primary key. All BigInt data types. Key value 1 and 2 have a range between 1 and 100. Key values 3 and 4 are auto incrementing values (forign key values) from other tables.
Space is an issue, so we have chosen not to have an additional column for a counter field for the PK. (We would never use the field for querying.)
Users complained of query speeds, so we added a couple non clustered indexs. This brought up the query speeds a lot. But of course it slowed down the input speed a bit. Nothing dramatic, but enough so we could tell.
Now the users was to increase the amount of data by about 5X. Obviosly I'm somewhat concerend, as SQL is already spending a lot of the day pegged.
So, in looking around, since the new indexes seem to be the most help in querying, I'm thinking of dropping the PK back to a nonclustered index, so I can get rid of the over head of restructring the data table on every insert. Then maybe making one of the other indexes the clustered index. (only 2 columns in this index)
Hi You know when you reread something you've read many times and a penny suddenly seems to drop and you realise that you probably just never quite got it afterall? If creating a nonclustered index with no includes statement it is totally pointless to specificy a fillfactor other than 0 or 100 if you do not also use the PAD_INDEX option? Thought I'd make it a poll just for the hell of it.:)
A few days after droping and recreating noclustered indexes on a large table, scan density of most indexes falls below 20%. Only a few number of rows has deleted. Update operation didn't update these keys and there was a lot of inserts. Could anyone explain why are indexes fragmented so much?
I have a scenario where I have 3 columns and all 3 of them are used in the where clauses of simple queries or ones having joins .
TABLE( Column1 int FLAG1 bit FLAG2 bit )
Sample queries :
Select * from TABLE where FLAG1 =1 and FLAG2 =0 (Any combination of these flags) Select * from TABLE inner join SOMEOTHERTABLE on TABLE.Column1 = SOMEOTHERTABLE .Column1 where FLAG1 =1 and FLAG2 =0
( any join and combination of flags)
Questions :
What would be the best nonclustered index strategy :
Column1 as the index key including FLAG1 and FLAG2 or Column1,FLAG1 and FLAG2 in the index key
Points to note :
The queries are part of an ETL process and are used to track new records vs old records. The Flags switch states within the same job . So if we are creating an index on all 3 columns, the index has to be reorganized more than once based on the flag states. If we keep them in the include list , then its only about updating the leaf data with the latest flag values.
On the other hand, an index on all 3 columns will result in an index Seek alone , where as for the included list , there will be an index seek and a predicate .
Does the predicate cause more overhead than reorganizing the index or is it the opposite ?
I have created one reports but all the records are displaying on one page.find a solution to display the records page by page. I created the same report without group so the records are displaying in page by page.
please explain the differences btween this logical & phisicall operations that we can see therir graphical icons in execution plan tab in Management Studio
Hello I have a project that uses a large number of MS Data access pages created in Access 2003 and runs on MS SQL2005.
When I am on lets say my client, (first page in a series) data access page and I have completed the fields in the (DAP), I am directing my users to the next step of the registration process by means of a hyperlink to another Data access page in the same web but in a linked or sometimes different table.
I need to pass data entered /created on the first page to the next page and populate the next page with some data from the first page / table. (like staying on the client name and ID when i go to the next page)
I also need the first data access page to open and display a blank or new record. Not an existing record. I will also be looking to creata a drop down box as a record selector.
Any pointers in the right direction would be appreciated. I am some what new to data access pages so a walk through would be nice but anything you got is welcome. Thanks Peter¦
I can't find any explanation why is it string1 and string 2 of the footer section of my report displayed separately from the expression3 which is aligned on it and the rest of the object on the second page.
The expected design is that all Footer items should be displayed together of whether it is placed on the first page or on the last page.
As a workaround of this, I converted string 1 into an expression (Added = and enclosed the string with double quote).. As a result, all of the items in the Footer section are now placed together on the last page of the report.
I also remember one of the issue I encountered before where the Footer items where placed together on the first page and still have space at the bottom of the page, but then expression 6 is forced to display (alone) on the last page of my report.
I can't find any discussion related to this, I wish somebody could give me an idea why RS behaved like this.
Fit an intere table in same page without page break for save the excel export.
My table has a Group for order my dates.
I need to have the intere table in the same page, i don't care about blank space at the end of the page.
I can't use the page break beacuse i need an excel export in a unique sheet.. I have tested.. every page break..you'll have a different sheet in your excel export
Hello, If I have a report that includes a page header, the report viewer will render the report at the full width, but if I hide the page header and show only the body it will use the absolute width of the report.
I have a 7" wide report, with .75" borders set on each side.
Interactive & Print size are set to 8.5x11 Changing these sizes has no effect on the behavior of the viewer, which appears to ignore them.
When I view this report in the local viewer the contents fill the window if there is no page header. If I enable the page header then the report is drawn at 8.5" wide, leaving a _big_ white border on the right side. Any comments or workarounds that anyone knows? I know the local viewer is not a standard configuration (at least it seems) but it is what we need to use.Thanks,//Andrew
How can I print a field that is in the dataset on each page? I added a textbox in the Page Header and use =Fields!ProjectName.value in the value property. I got an error "Fields cannot used in page header and footer."
How can I have the table header shows on each page? Currently if the data goes to the second page, there is no table header.
When i view the Report from SSRS Report preview Tab it's working fine, But when i deploy that and try to view in the IE I am seeing the Body background color in between the image and page border of the page footer how to solve that?