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

Wednesday, March 28, 2012

Information needed on jobs !

Hi
I please need your help on jobs. I am new to it !
For all our world wide customers, I need to have a sql
script that will create a job to be run on each production
database. This will just call a stored procedure that
will update data in that DB.
1) what minimum permissions or roles are needed to create
a job ?
2) NB NB:: can a job be scheduled to run based on the
results of a sql stamenent ?
E.g. run every getdate() + (select no_of_days from .....)
Your help is appreciated immensely !!
Thanks
Tania1. Anybody in public role can create a job.
2. I am not sure if I understood this correctly or not. You can write a
cursor/loop to iterate through each rows in your resultset and call the
sp_add_jobschedule/sp_update_jobschedule procedures. If you are asking about
running a job, you can use the sp_start_job stored procedure. All details
regarding these procedures can be found in SQL Server Books Online.
--
- Anith
( Please reply to newsgroups only )

Information about an SQL server

i would like to create a Store procedure that can put the following
information into a database.
1.) Version of SQL on that instance
2.) Version of Windows including SPs (can i get this from SQL?)
3.) Size of each log file on the server instance
I would like to out this information to a database which i will connect to
via ASP so that it can be displayed on our Intranet .hi
can u check
select @.@.version
this will give u info that u require
best Regards,
Chandra
http://chanduas.blogspot.com/
http://www.SQLResource.com/
---
"Nick Pennisi" wrote:

> i would like to create a Store procedure that can put the following
> information into a database.
> 1.) Version of SQL on that instance
> 2.) Version of Windows including SPs (can i get this from SQL?)
> 3.) Size of each log file on the server instance
> I would like to out this information to a database which i will connect to
> via ASP so that it can be displayed on our Intranet .|||For the first two questions, use SELECT @.@.VERSION.
For the third question, use:
SELECT filename, size*8192 as filesize FROM master..sysaltfiles
Razvan|||1) You can parse SELECT @.@.VERSION
2) You can parse SELECT @.@.VERSION
3) see the following:
CREATE TABLE #logfiles
(
dbid int,
fileid int,
groupid int,
size bigint,
maxsize bigint,
growth bigint,
status bigint,
perf int,
name sysname,
filename sysname
)
EXEC sp_msForEachDB 'INSERT #logfiles SELECT DB_ID(N''?''),* FROM
[?]..sysfiles'
SELECT db_name(dbid),size,name,filename
FROM #logfiles
WHERE status & 0x40 = 0x40 -- log file
ORDER BY 1, name
DROP TABLE #logfiles
"Nick Pennisi" <NickPennisi@.discussions.microsoft.com> wrote in message
news:F041A69E-3057-458A-8FB0-DA1BAB8A2DFB@.microsoft.com...
>i would like to create a Store procedure that can put the following
> information into a database.
> 1.) Version of SQL on that instance
> 2.) Version of Windows including SPs (can i get this from SQL?)
> 3.) Size of each log file on the server instance
> I would like to out this information to a database which i will connect to
> via ASP so that it can be displayed on our Intranet .|||1 and 2 = SELECT @.@.VERSION
3 = sp_helpdb dbname
"Nick Pennisi" <NickPennisi@.discussions.microsoft.com> wrote in message
news:F041A69E-3057-458A-8FB0-DA1BAB8A2DFB@.microsoft.com...
>i would like to create a Store procedure that can put the following
> information into a database.
> 1.) Version of SQL on that instance
> 2.) Version of Windows including SPs (can i get this from SQL?)
> 3.) Size of each log file on the server instance
> I would like to out this information to a database which i will connect to
> via ASP so that it can be displayed on our Intranet .|||Try these 2 queries:
SELECT @.@.version
SELECT *
FROM master..sysaltfiles(nolock)
WHERE groupid = 0
"Nick Pennisi" <NickPennisi@.discussions.microsoft.com> wrote in message news:F041A69E-3057-
458A-8FB0-DA1BAB8A2DFB@.microsoft.com...
>i would like to create a Store procedure that can put the following
> information into a database.
>
> 1.) Version of SQL on that instance
> 2.) Version of Windows including SPs (can i get this from SQL?)
> 3.) Size of each log file on the server instance
>
> I would like to out this information to a database which i will connect to
> via ASP so that it can be displayed on our Intranet .|||1) select @.@.version
Hope this helps
Cheers,
JP
--
"Nick Pennisi" <NickPennisi@.discussions.microsoft.com> wrote in message
news:F041A69E-3057-458A-8FB0-DA1BAB8A2DFB@.microsoft.com...
>i would like to create a Store procedure that can put the following
> information into a database.
> 1.) Version of SQL on that instance
> 2.) Version of Windows including SPs (can i get this from SQL?)
> 3.) Size of each log file on the server instance
> I would like to out this information to a database which i will connect to
> via ASP so that it can be displayed on our Intranet .|||xp_msver
Returns and allows to be queried Microsoft SQL ServerT version information.
In addition to version information regarding the actual build number of the
server, various environment information is also returned. This information
can be used within Transact-SQL statements, batches, stored procedures, and
so on, to enhance logic for platform-independent code.
Syntax
xp_msver [optname]
Arguments
optname
Is the name of an option, and can be one of the following.
Option/Column name Description
ProductName Product name; for example, Microsoft SQL Server.
ProductVersion Product version; for example, 7.00.419 where 7.00 is
the version and 419 is the Microsoft internal build number.
Language The language version of SQL Server.
Platform Operating-system name, manufacturer name, and chip family
name for the computer running SQL Server. For example, NT INTEL X86
indicates Microsoft Windows NT as the operating system, Intel as the chip
manufacturer, and a 486 or higher processor.
Comments Miscellaneous information about SQL Server.
CompanyName Company name that produces SQL Server; for example,
Microsoft Corporation.
FileDescription The operating system.
FileVersion Version of the SQL Server executable. For example,
1998.02.01 indicates a file version of February 1, 1998, on the Sqlservr.exe
file.
InternalName Microsoft internal name for SQL Server; for example,
SQLSERVR.
LegalCopyright Legal copyright information required for SQL Server;
for example, Copyright Microsoft Corp. 1998.
LegalTrademarks Legal trademark information required for SQL Server.
For example, Microsoft is a registered trademark of Microsoft Corporation.
OriginalFilename File name executed at SQL Server startup; for
example, Sqlservr.exe.
PrivateBuild Reserved.
SpecialBuild Reserved.
WindowsVersion Microsoft Windows version installed on the computer
running SQL Server. For example, 4.0 indicates version 4.0 of Microsoft
Windows NT, and 1381 indicates the internal build number.
ProcessorCount The number of processors in the computer running SQL
Server.
ProcessorActiveMask Indicates what processors installed in the
computer running SQL Server are activated and usable by Microsoft Windows
NT.
ProcessorType Processor type. Similar to Platform.
PhysicalMemory Amount in megabytes (MB) of RAM installed on the
computer running SQL Server. For example, 32 indicates 32 MB of RAM.
Product ID Product ID (PID) number, which is specified during
installation. This number is located on a sticker on the original SQL Server
compact disc case.
Return Code Values
0 (success) or 1 (failure)
Result Sets
xp_msver, without any parameters, returns this four-column result set
(values may vary):
Index Name Internal_Value Character_Value
-- -- -- --
1 ProductName NULL Microsoft SQL
Server
2 ProductVersion 458752 7.00.498
3 Language 1033 English (United
States)
4 Platform NULL NT INTEL X86
5 Comments NULL NT INTEL X86
6 CompanyName NULL Microsoft
Corporation
7 FileDescription NULL SQL Server
Windows NT
8 FileVersion NULL 1998.05.25
9 InternalName NULL SQLSERVR
10 LegalCopyright NULL Copyright
Microsoft Corp. 1998
11 LegalTrademarks NULL Microsoft is a
registered trademark of
Microsoft Corporation. Windows(TM) is
a trademark of Microsoft
Corporation
12 OriginalFilename NULL SQLSERVR.EXE
13 PrivateBuild NULL NULL
14 SpecialBuild 262242 NULL
15 WindowsVersion 90505220 4.0 (1381)
16 ProcessorCount 1 1
17 ProcessorActiveMask 1 00000001
18 ProcessorType 586 PROCESSOR_INTEL_PENTIUM
19 PhysicalMemory 63 63 (66510848)
20 Product ID NULL NULL
(20 row(s) affected)
xp_msver, for any option, returns the four-column headings with values for
that option. For example, this result set is returned when xp_msver is
executed with the FileDescription option.
xp_msver FileDescription
Index Name Internal_Value Character_Value
-- -- -- --
7 FileDescription NULL SQL Server Windows NT
(1 row(s) affected)
Permissions
Execute permissions default to the public role.
See Also
System Functions
System Stored Procedures (General Extended Procedures)
@.@.VERSION
1988-2000 Microsoft Corporation. All Rights Reserved
"Nick Pennisi" <NickPennisi@.discussions.microsoft.com> wrote in message
news:F041A69E-3057-458A-8FB0-DA1BAB8A2DFB@.microsoft.com...
>i would like to create a Store procedure that can put the following
> information into a database.
> 1.) Version of SQL on that instance
> 2.) Version of Windows including SPs (can i get this from SQL?)
> 3.) Size of each log file on the server instance
> I would like to out this information to a database which i will connect to
> via ASP so that it can be displayed on our Intranet .

Friday, March 23, 2012

Indicator non aggregate

Hi everybody,

I'm working on SQL Server 2005 & Reporting services to create a Projet model to deploy it on the server.

To explain me, i 'll recreate simply my problem on the the database "AdventureWorksDW".

I woudl like to see information on my product dimension.

In a matrix tab, i put "Product name" in row value and "customer name" on column.

I would naturally know the "Sales Amount" for my product by customers.

But, as i had not create aggregate, i can't put my numerique value on the cells indicators. It just allowed me to put the SUM(SALES_AMOUNT) by exemple, but it's not what i want.

How can i put my numerique value in this case ?

Regards,

Erwan

Toulouse, France

Have a column called count on the fact table.

Have the value 1 in the column

Sum the column

|||

The probleme is that i dont want the sum of my value, in just want the pure value.

It is possible ?

Erwan

|||

The whole point of a matrix is that it aggregates the data.

Otherwise it would be a table.

In analysis services, you can drillthrough to the underlying data in the fact table. You would need to post on that forum to find out how.

|||

it's ok, i had just execute my request to blind total.

Thanks adolf

sql

Wednesday, March 21, 2012

Indian language kannada not exporting as PDF

Hi all,
We are devloping reports in the regional language. When we create a report
for the indian language kannada we are not able to see the text we are only
seeing "?" . Our OS is Windows XP and when we export reports to tiff format
we are able to see the kannada characters.
can you helpTo start with, make sure that exact font is available on both the server and
all the clients that attempt to view the PDF file. We do not embed the
fonts into the PDF documents.
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Srini" <Srini@.discussions.microsoft.com> wrote in message
news:E7A0B237-BF36-4228-86BB-C20D00A9DCD0@.microsoft.com...
> Hi all,
> We are devloping reports in the regional language. When we create a report
> for the indian language kannada we are not able to see the text we are
> only
> seeing "?" . Our OS is Windows XP and when we export reports to tiff
> format
> we are able to see the kannada characters.
> can you help

INDEXTYPE equivalent ?

Hi,

There is a concept called INDEXTYPE in Oracle, Is there any equivallent for the same in SQL Server ?

Oracle example :

CREATE INDEX index1 ON test_table(col1) INDEXTYPE IS CTXSYS.CONTEXT

What is the SQL Server equivalent query for the above ?

Thanks,
SamI'm not enirely sure as to what exactly indextypes in Oracle are. As far as I know its a more narrow definition of how the column/s in the index could be used in when/like clauses and is build to that. Searches such as when client = 'Kaiowas', like 'Kai%s' or 'K%w%s'. Ms SQLServer does not have this kind of performance tuning as far as I know, perhaps Ms SQLServer depends more on it's internal query-plans.sql

Monday, March 19, 2012

Indexing on Views

1) We have SQL Server 2005 database on windows 2003 server.

2) What about columns in functions i.e. SUM(ABS(Col1)) OR SUM(Col2 * Col3). We create a view to select these and index on view on its computed AS column? Can we directly use vw1.AScol in query in place of these function expressions? Will the index be picked and how will cost improvement compare with that of index on normal columns.

3) Can statistics be used in such a situation?

its possible to put indexes on this columns...and it will be picked .... have a look at this link.:

http://www.microsoft.com/technet/prodtechnol/sql/2005/impprfiv.mspx

Monday, March 12, 2012

Indexing a view that contains text or ntext

I've created a view and started to create my first index (unique, clustered)
but got the following error:
"Cannot create index on view 'MyDB.dbo.myview'. It contains text, ntext,
image or xml columns. (Mircrosoft SQL Server, Error: 1492)"
There is only one field among the fields I'm using that is ntext.
Unfortunately I don't see how I can change it's data type since the largest
number of characters in this field is over 22,000 characters. What are my
options for creating indexes on this view? Is there a workaround that I can
do? Any suggestions?
Hi
From BOL: "Note Columns consisting of the ntext, text, or image data types
cannot be specified as columns for an index. In addition, a view cannot
include any text, ntext, or image columns, even if they are not referenced in
the CREATE INDEX statement."
Therefore with your current view you can not create an index. Does this
column need to be in the view?
John
"archuleta37" wrote:

> I've created a view and started to create my first index (unique, clustered)
> but got the following error:
> "Cannot create index on view 'MyDB.dbo.myview'. It contains text, ntext,
> image or xml columns. (Mircrosoft SQL Server, Error: 1492)"
> There is only one field among the fields I'm using that is ntext.
> Unfortunately I don't see how I can change it's data type since the largest
> number of characters in this field is over 22,000 characters. What are my
> options for creating indexes on this view? Is there a workaround that I can
> do? Any suggestions?

Indexing a view that contains text or ntext

I've created a view and started to create my first index (unique, clustered)
but got the following error:
"Cannot create index on view 'MyDB.dbo.myview'. It contains text, ntext,
image or xml columns. (Mircrosoft SQL Server, Error: 1492)"
There is only one field among the fields I'm using that is ntext.
Unfortunately I don't see how I can change it's data type since the largest
number of characters in this field is over 22,000 characters. What are my
options for creating indexes on this view? Is there a workaround that I can
do? Any suggestions?Hi
From BOL: "Note Columns consisting of the ntext, text, or image data types
cannot be specified as columns for an index. In addition, a view cannot
include any text, ntext, or image columns, even if they are not referenced i
n
the CREATE INDEX statement."
Therefore with your current view you can not create an index. Does this
column need to be in the view?
John
"archuleta37" wrote:

> I've created a view and started to create my first index (unique, clustere
d)
> but got the following error:
> "Cannot create index on view 'MyDB.dbo.myview'. It contains text, ntext,
> image or xml columns. (Mircrosoft SQL Server, Error: 1492)"
> There is only one field among the fields I'm using that is ntext.
> Unfortunately I don't see how I can change it's data type since the larges
t
> number of characters in this field is over 22,000 characters. What are my
> options for creating indexes on this view? Is there a workaround that I ca
n
> do? Any suggestions?

Indexing a view that contains text or ntext

I've created a view and started to create my first index (unique, clustered)
but got the following error:
"Cannot create index on view 'MyDB.dbo.myview'. It contains text, ntext,
image or xml columns. (Mircrosoft SQL Server, Error: 1492)"
There is only one field among the fields I'm using that is ntext.
Unfortunately I don't see how I can change it's data type since the largest
number of characters in this field is over 22,000 characters. What are my
options for creating indexes on this view? Is there a workaround that I can
do? Any suggestions?Hi
From BOL: "Note Columns consisting of the ntext, text, or image data types
cannot be specified as columns for an index. In addition, a view cannot
include any text, ntext, or image columns, even if they are not referenced in
the CREATE INDEX statement."
Therefore with your current view you can not create an index. Does this
column need to be in the view?
John
"archuleta37" wrote:
> I've created a view and started to create my first index (unique, clustered)
> but got the following error:
> "Cannot create index on view 'MyDB.dbo.myview'. It contains text, ntext,
> image or xml columns. (Mircrosoft SQL Server, Error: 1492)"
> There is only one field among the fields I'm using that is ntext.
> Unfortunately I don't see how I can change it's data type since the largest
> number of characters in this field is over 22,000 characters. What are my
> options for creating indexes on this view? Is there a workaround that I can
> do? Any suggestions?

Indexing - What is fastest? Numeric or Alpha fields?

If I create an index on a field in SQL Server, what will be the most efficient (fastest) field type to index a field? (This field will be a "Pointer" to a child table that will contain a list of codes, and their description.)

Would a Numeric field be quicker than a VarChar field?

VarChar would make it easier for a Human to decipher the raw records. (For example, if I used a numeric the code would be 42 or 47, while the VarChar could be'savings' or'checking'.)

Basically I will have the following "Master" table:

FieldType---IDIntNameVarCharStatusInt -or- VarCharCustomer_TypeInt -or- VarChar

If Customer_Type is a code that can be looked up in another table, and I index that field, would I want the "Code" to be an Int or VarChar?

SQL:

Select *From MasterWhere Customer_Type = <42> or <'savings'>

MyWhereclause would depend on the field type.

Thank you,
Bryan

Int.

Indexing

Hi,
Could someone please tell me the "best" way to index a table? Is the best
way (defined as quickest access to data) to create an index on every field
individually that might be queried, or is it best to create an index that
contains multiple fields if that's how they appear after the WHERE clause.
Thanks,
SteveHi Steve
Check out
http://www.sql-server-performance.com/mr_indexing.asp
http://www.sql-server-performance.c...ance_audit7.asp
http://www.sql-server-performance.c..._structures.asp
What the article doesn't specify is that it is always worth running the
index tuning wizard just to see what it comes up with, in case you may have
missed something or alternatively as a starting point. I would use this for
analysis and implement the suggestions you believe to be suitable rather tha
n
implement them verbatim.
John
"Steve Caliendo" wrote:

> Hi,
> Could someone please tell me the "best" way to index a table? Is the best
> way (defined as quickest access to data) to create an index on every field
> individually that might be queried, or is it best to create an index that
> contains multiple fields if that's how they appear after the WHERE clause.
> Thanks,
> Steve
>
>

Friday, March 9, 2012

INDEXIES – Inserting of large amount of records

Is there any way how to create indexies after insertion of anynumber of records (I dont want to create index after insertion of every record,but for example after insertion of 1000 records) ?

I heard it should be possible with ?bulk insert" or withtransactions. Is it right ? I need do this with MS SQL Server 2005 (Workgroupedition).

Thank you for your ideas!

Jan

You could add a trigger to the table to fire on Inserts.

In the trigger, you could count the number of rows in the table.

If the number of rows is greater than 1000, use SQL "Create Index..." to create an index (check first to make sure it doesn't already exist).

But I don't understand this request. Why not create the index when the table is created?

It's true having an index will slow down inserts and on small tables will not help lookup speed much. But having to do a row count on each insert will also cause inserts to be slower.

|||If you are using SQL 2005 you might as well take advantage of the ONLINE Indexing. Bulk Insert/Transactions will not initiate any Index creation. You need to manually create the Index. And creating an Index from Trigger is not such a good idea. You might as well create a job that runs every 2-3 hrs and does a count on the table and then creates the index if the appropriate row count is reached. Understand however, that index creation is a resource intensive process. It will lock up the tables during the process of index creation.|||

Sorry, I expressed myself badly, I dont need create indexies, I meant rebuild indexies. .

The reason is that rebuilding indexies take some time andperformance so that is why I would like rebuild them just afterinsertion of any number of records (not every time).

Is there any way how to do this?

Thank you,
Jan

|||

I think you can set it up as a Maintanence Plan Task:

Use the Rebuild Index Task dialog to re-create the indexes on the tables in the database with a new fill factor. The fill factor determines the amount of empty space on each page in the index, to accommodate future expansion. As data is added to the table, the free space fills because the fill factor is not maintained. Reorganizing data and index pages can re-establish the free space.

Maintenance plans can be used to create a workflow of the maintenance tasks required to make sure that your database performs well, is regularly backed up in case of system failure, and is checked for inconsistencies. Although the Maintenance Plan Wizard can be used for creating core maintenance plans, creating these plans manually gives you much more flexibility. In SQL Server 2005 Database Engine, maintenance plans create a SQL Server Agent job that performs these maintenance tasks automatically at scheduled intervals.

|||As SGWellems mentioned you can set up a job to rebuild the indexes..depending on how many records get inserted/deleted/modified everyday you could set it to run every night or during the weekends. I wuold recommend dropping and recreating the index. This will also remove any fragmentation in the indexes.

INDEXES: Is this correct

I have a temp table and created two indexes on it.
Please See below
--
CREATE TABLE #Invoice (
InvoiceID int NOT NULL,
CustomerKey varchar(20),
DebtorId int,
Reference varchar(50),
BalanceDue money,
DebtID int,
Reason varchar(100),
DebtStatus int,
)
CREATE INDEX idxInvoice ON #Invoice (InvoiceID)
CREATE INDEX idxInvoice2 ON #Invoice (DebtID)
---
I use DebtID as index because I use it again as a inner join to this table
in another query. So I assume it will make much faster. All I want to know is
would this code work?> All I want to know is would this code work?
Well, did you try it? What happened?
--
http://www.aspfaq.com/
(Reverse address to reply.)

Indexes on temp tables in stored procs

I've learned that, to help prevent/minimize proc recompiles, it is best to create all needed temp tables first, before doing anything else in the sproc.

What about indexes on those temp tables? Is it better to create the index immediately after each temp table is created, or is it better to create all the temp tables first, then create all the indexes?

Since you don't have data in your temp tables at either point, it really doesn't matter that much. You'll have some metadata operations to do if you convert from a heap to a clustered index later on, but the cost will be miniscule, and virtually undetectable.

Thanks,
Ryan Stonecipher
Microsoft SQL Server Storage Engine

Wednesday, March 7, 2012

Indexes on Joined Columns

I have the following select statement used to create a view:
select
st.col1,
st.col2
from
FirstTable ft
inner join
SecondTable st
on
ft.coluid = st.colfid
and
ft.colkey = st.colkey
My statistics are up to date.
On FirstTable I have a clustered (Unique) primary key comprised of a
composite of coluid and colkey (in that order) having 64,000 rows. Column
coluid has a selectivity ratio of 0.94 and colkey has a selectivity ratio of
0.
On SecondTable I have a clustered (non unique) primary key comprised of a
composite of colfid and colkey (in that order) having 168,000 rows. Column
colfid has a selectivity ratio of 0.35 and colkey has a selectivity ratio of
0.
The two columns returned (st.col1, st.col2) from the select statement are not
indexed.
I was under the impression from various readings that having indexes on joins
are beneficial, but in testing, when I have the clustered indexes, versus
dropping the indexes and running the select statement, there is no difference
in the output of statistics io.
Also the execution plan states that each table receives a clustered index
scan.
The only benefit I see from having indexes on the joins is in CPU time, with
indexes 187 ms., without 375 ms.
Is that the benefit (reduced CPU, but no reduction of Logical Reads) spoken
of when I read that indexes on joined columns are beneficial? Also, wouldn't
my two columns returned be covered by the clustered index, if the index were
ever used?
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200605/1Um, basically, you want the entire contents of both tables. How about
filtering in some way? Also. if you are using SQL Server 2000, try adding
clustered index on (st.colfid, st.colkey, st.col1, st.col2). If you have
SQL 2005, create the nonclustered on (st.col1, st.col2) with included
columns on (st.colfid, st.colkey).
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message
news:60c001bcd2645@.uwe...
I have the following select statement used to create a view:
select
st.col1,
st.col2
from
FirstTable ft
inner join
SecondTable st
on
ft.coluid = st.colfid
and
ft.colkey = st.colkey
My statistics are up to date.
On FirstTable I have a clustered (Unique) primary key comprised of a
composite of coluid and colkey (in that order) having 64,000 rows. Column
coluid has a selectivity ratio of 0.94 and colkey has a selectivity ratio of
0.
On SecondTable I have a clustered (non unique) primary key comprised of a
composite of colfid and colkey (in that order) having 168,000 rows. Column
colfid has a selectivity ratio of 0.35 and colkey has a selectivity ratio of
0.
The two columns returned (st.col1, st.col2) from the select statement are
not
indexed.
I was under the impression from various readings that having indexes on
joins
are beneficial, but in testing, when I have the clustered indexes, versus
dropping the indexes and running the select statement, there is no
difference
in the output of statistics io.
Also the execution plan states that each table receives a clustered index
scan.
The only benefit I see from having indexes on the joins is in CPU time, with
indexes 187 ms., without 375 ms.
Is that the benefit (reduced CPU, but no reduction of Logical Reads) spoken
of when I read that indexes on joined columns are beneficial? Also, wouldn't
my two columns returned be covered by the clustered index, if the index were
ever used?
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200605/1|||A clustered index scan is a table scan, so that is no surprise.
You cannot use statistics IO to tell which is the better plan. As you have
noticed, the IO is the same, but the CPU is different. What kind of join
does the plan say is being performed? Without indexes, my guess is that
you're getting a hash join, which does a single pass through each table
while it builds and analyzes hash lists. So the IO is only one pass through
each table. But the extra work of building and examining the hash lists, but
the extra memory required to stored the hashed information, can make that
type of join very resource intensive.
--
HTH
Kalen Delaney, SQL Server MVP
"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message
news:60c001bcd2645@.uwe...
>I have the following select statement used to create a view:
> select
> st.col1,
> st.col2
> from
> FirstTable ft
> inner join
> SecondTable st
> on
> ft.coluid = st.colfid
> and
> ft.colkey = st.colkey
> My statistics are up to date.
> On FirstTable I have a clustered (Unique) primary key comprised of a
> composite of coluid and colkey (in that order) having 64,000 rows. Column
> coluid has a selectivity ratio of 0.94 and colkey has a selectivity ratio
> of
> 0.
> On SecondTable I have a clustered (non unique) primary key comprised of a
> composite of colfid and colkey (in that order) having 168,000 rows. Column
> colfid has a selectivity ratio of 0.35 and colkey has a selectivity ratio
> of
> 0.
> The two columns returned (st.col1, st.col2) from the select statement are
> not
> indexed.
> I was under the impression from various readings that having indexes on
> joins
> are beneficial, but in testing, when I have the clustered indexes, versus
> dropping the indexes and running the select statement, there is no
> difference
> in the output of statistics io.
> Also the execution plan states that each table receives a clustered index
> scan.
> The only benefit I see from having indexes on the joins is in CPU time,
> with
> indexes 187 ms., without 375 ms.
> Is that the benefit (reduced CPU, but no reduction of Logical Reads)
> spoken
> of when I read that indexes on joined columns are beneficial? Also,
> wouldn't
> my two columns returned be covered by the clustered index, if the index
> were
> ever used?
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200605/1|||I follow your logic in SQL Server 2000, of adding a clustered index on (st.
colfid, st.colkey, st.col1, st.col2). But I am not sure about your statement
regarding SQL 2005. Are you saying create a nonclustered index on (st.col1,
st.col2, st.colfid, st.colkey)? If so, what is the difference between the
indexing from SQL 2000 to SQL 2005 that would make you want to cluster in SQL
2000 and adding an additional nonclustered index in SQL 2005?
Tom Moreau wrote:
>Also. if you are using SQL Server 2000, try adding
>clustered index on (st.colfid, st.colkey, st.col1, st.col2). If you have
>SQL 2005, create the nonclustered on (st.col1, st.col2) with included
>columns on (st.colfid, st.colkey).
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200605/1|||I am receiving a merge join, with clustered index scans when the clustered
indexes are in use. Additionally I can change the clustered index scan for
the node representing FirstTable when I apply the filter "where ft.coluid >
0".
When the clustered indexes are removed I have table scans and a hash join.
Kalen Delaney wrote:
>A clustered index scan is a table scan, so that is no surprise.
>You cannot use statistics IO to tell which is the better plan. As you have
>noticed, the IO is the same, but the CPU is different. What kind of join
>does the plan say is being performed? Without indexes, my guess is that
>you're getting a hash join, which does a single pass through each table
>while it builds and analyzes hash lists. So the IO is only one pass through
>each table. But the extra work of building and examining the hash lists, but
>the extra memory required to stored the hashed information, can make that
>type of join very resource intensive.
>>I have the following select statement used to create a view:
>[quoted text clipped - 49 lines]
>> were
>> ever used?
--
Message posted via http://www.sqlmonster.com|||Sorry, I wasn't clear. I can change the clustered index scan for the node
representing FirstTable when I apply the filter "where ft.coluid 0" to a
clustered index seek.
cbrichards wrote:
>I am receiving a merge join, with clustered index scans when the clustered
>indexes are in use. Additionally I can change the clustered index scan for
>the node representing FirstTable when I apply the filter "where ft.coluid >
>0".
>When the clustered indexes are removed I have table scans and a hash join.
>>A clustered index scan is a table scan, so that is no surprise.
>>You cannot use statistics IO to tell which is the better plan. As you have
>[quoted text clipped - 11 lines]
>> were
>> ever used?
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200605/1|||In SQL 2005, you have the option of "included columns". This makes covering
indexes more efficient, since the included columns exist only in the leaf
pages of the index. Basically, make the criteria from your JOIN and WHERE
clauses to be your index keys. Then make the included columns to be any
other columns from your SELECT list that don't already exist in your index
keys.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"cbrichards via SQLMonster.com" <u3288@.uwe> wrote in message
news:60c845387d9c4@.uwe...
I follow your logic in SQL Server 2000, of adding a clustered index on (st.
colfid, st.colkey, st.col1, st.col2). But I am not sure about your
statement
regarding SQL 2005. Are you saying create a nonclustered index on (st.col1,
st.col2, st.colfid, st.colkey)? If so, what is the difference between the
indexing from SQL 2000 to SQL 2005 that would make you want to cluster in
SQL
2000 and adding an additional nonclustered index in SQL 2005?
Tom Moreau wrote:
>Also. if you are using SQL Server 2000, try adding
>clustered index on (st.colfid, st.colkey, st.col1, st.col2). If you have
>SQL 2005, create the nonclustered on (st.col1, st.col2) with included
>columns on (st.colfid, st.colkey).
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server/200605/1

Indexes on Joined Columns

I have the following select statement used to create a view:
select
st.col1,
st.col2
from
FirstTable ft
inner join
SecondTable st
on
ft.coluid = st.colfid
and
ft.colkey = st.colkey
My statistics are up to date.
On FirstTable I have a clustered (Unique) primary key comprised of a
composite of coluid and colkey (in that order) having 64,000 rows. Column
coluid has a selectivity ratio of 0.94 and colkey has a selectivity ratio of
0.
On SecondTable I have a clustered (non unique) primary key comprised of a
composite of colfid and colkey (in that order) having 168,000 rows. Column
colfid has a selectivity ratio of 0.35 and colkey has a selectivity ratio of
0.
The two columns returned (st.col1, st.col2) from the select statement are no
t
indexed.
I was under the impression from various readings that having indexes on join
s
are beneficial, but in testing, when I have the clustered indexes, versus
dropping the indexes and running the select statement, there is no differenc
e
in the output of statistics io.
Also the execution plan states that each table receives a clustered index
scan.
The only benefit I see from having indexes on the joins is in CPU time, with
indexes 187 ms., without 375 ms.
Is that the benefit (reduced CPU, but no reduction of Logical Reads) spoken
of when I read that indexes on joined columns are beneficial? Also, wouldn't
my two columns returned be covered by the clustered index, if the index were
ever used?
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200605/1Um, basically, you want the entire contents of both tables. How about
filtering in some way? Also. if you are using SQL Server 2000, try adding
clustered index on (st.colfid, st.colkey, st.col1, st.col2). If you have
SQL 2005, create the nonclustered on (st.col1, st.col2) with included
columns on (st.colfid, st.colkey).
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:60c001bcd2645@.uwe...
I have the following select statement used to create a view:
select
st.col1,
st.col2
from
FirstTable ft
inner join
SecondTable st
on
ft.coluid = st.colfid
and
ft.colkey = st.colkey
My statistics are up to date.
On FirstTable I have a clustered (Unique) primary key comprised of a
composite of coluid and colkey (in that order) having 64,000 rows. Column
coluid has a selectivity ratio of 0.94 and colkey has a selectivity ratio of
0.
On SecondTable I have a clustered (non unique) primary key comprised of a
composite of colfid and colkey (in that order) having 168,000 rows. Column
colfid has a selectivity ratio of 0.35 and colkey has a selectivity ratio of
0.
The two columns returned (st.col1, st.col2) from the select statement are
not
indexed.
I was under the impression from various readings that having indexes on
joins
are beneficial, but in testing, when I have the clustered indexes, versus
dropping the indexes and running the select statement, there is no
difference
in the output of statistics io.
Also the execution plan states that each table receives a clustered index
scan.
The only benefit I see from having indexes on the joins is in CPU time, with
indexes 187 ms., without 375 ms.
Is that the benefit (reduced CPU, but no reduction of Logical Reads) spoken
of when I read that indexes on joined columns are beneficial? Also, wouldn't
my two columns returned be covered by the clustered index, if the index were
ever used?
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200605/1|||A clustered index scan is a table scan, so that is no surprise.
You cannot use statistics IO to tell which is the better plan. As you have
noticed, the IO is the same, but the CPU is different. What kind of join
does the plan say is being performed? Without indexes, my guess is that
you're getting a hash join, which does a single pass through each table
while it builds and analyzes hash lists. So the IO is only one pass through
each table. But the extra work of building and examining the hash lists, but
the extra memory required to stored the hashed information, can make that
type of join very resource intensive.
HTH
Kalen Delaney, SQL Server MVP
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:60c001bcd2645@.uwe...
>I have the following select statement used to create a view:
> select
> st.col1,
> st.col2
> from
> FirstTable ft
> inner join
> SecondTable st
> on
> ft.coluid = st.colfid
> and
> ft.colkey = st.colkey
> My statistics are up to date.
> On FirstTable I have a clustered (Unique) primary key comprised of a
> composite of coluid and colkey (in that order) having 64,000 rows. Column
> coluid has a selectivity ratio of 0.94 and colkey has a selectivity ratio
> of
> 0.
> On SecondTable I have a clustered (non unique) primary key comprised of a
> composite of colfid and colkey (in that order) having 168,000 rows. Column
> colfid has a selectivity ratio of 0.35 and colkey has a selectivity ratio
> of
> 0.
> The two columns returned (st.col1, st.col2) from the select statement are
> not
> indexed.
> I was under the impression from various readings that having indexes on
> joins
> are beneficial, but in testing, when I have the clustered indexes, versus
> dropping the indexes and running the select statement, there is no
> difference
> in the output of statistics io.
> Also the execution plan states that each table receives a clustered index
> scan.
> The only benefit I see from having indexes on the joins is in CPU time,
> with
> indexes 187 ms., without 375 ms.
> Is that the benefit (reduced CPU, but no reduction of Logical Reads)
> spoken
> of when I read that indexes on joined columns are beneficial? Also,
> wouldn't
> my two columns returned be covered by the clustered index, if the index
> were
> ever used?
> --
> Message posted via droptable.com
> http://www.droptable.com/Uwe/Forum...server/200605/1|||I follow your logic in SQL Server 2000, of adding a clustered index on (st.
colfid, st.colkey, st.col1, st.col2). But I am not sure about your statemen
t
regarding SQL 2005. Are you saying create a nonclustered index on (st.col1,
st.col2, st.colfid, st.colkey)? If so, what is the difference between the
indexing from SQL 2000 to SQL 2005 that would make you want to cluster in SQ
L
2000 and adding an additional nonclustered index in SQL 2005?
Tom Moreau wrote:
>Also. if you are using SQL Server 2000, try adding
>clustered index on (st.colfid, st.colkey, st.col1, st.col2). If you have
>SQL 2005, create the nonclustered on (st.col1, st.col2) with included
>columns on (st.colfid, st.colkey).
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200605/1|||I am receiving a merge join, with clustered index scans when the clustered
indexes are in use. Additionally I can change the clustered index scan for
the node representing FirstTable when I apply the filter "where ft.coluid >
0".
When the clustered indexes are removed I have table scans and a hash join.
Kalen Delaney wrote:[vbcol=seagreen]
>A clustered index scan is a table scan, so that is no surprise.
>You cannot use statistics IO to tell which is the better plan. As you have
>noticed, the IO is the same, but the CPU is different. What kind of join
>does the plan say is being performed? Without indexes, my guess is that
>you're getting a hash join, which does a single pass through each table
>while it builds and analyzes hash lists. So the IO is only one pass through
>each table. But the extra work of building and examining the hash lists, bu
t
>the extra memory required to stored the hashed information, can make that
>type of join very resource intensive.
>
>[quoted text clipped - 49 lines]
Message posted via http://www.droptable.com|||Sorry, I wasn't clear. I can change the clustered index scan for the node
representing FirstTable when I apply the filter "where ft.coluid 0" to a
clustered index seek.
cbrichards wrote:[vbcol=seagreen]
>I am receiving a merge join, with clustered index scans when the clustered
>indexes are in use. Additionally I can change the clustered index scan for
>the node representing FirstTable when I apply the filter "where ft.coluid >
>0".
>When the clustered indexes are removed I have table scans and a hash join.
>
>[quoted text clipped - 11 lines]
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200605/1|||In SQL 2005, you have the option of "included columns". This makes covering
indexes more efficient, since the included columns exist only in the leaf
pages of the index. Basically, make the criteria from your JOIN and WHERE
clauses to be your index keys. Then make the included columns to be any
other columns from your SELECT list that don't already exist in your index
keys.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Toronto, ON Canada
.
"cbrichards via droptable.com" <u3288@.uwe> wrote in message
news:60c845387d9c4@.uwe...
I follow your logic in SQL Server 2000, of adding a clustered index on (st.
colfid, st.colkey, st.col1, st.col2). But I am not sure about your
statement
regarding SQL 2005. Are you saying create a nonclustered index on (st.col1,
st.col2, st.colfid, st.colkey)? If so, what is the difference between the
indexing from SQL 2000 to SQL 2005 that would make you want to cluster in
SQL
2000 and adding an additional nonclustered index in SQL 2005?
Tom Moreau wrote:
>Also. if you are using SQL Server 2000, try adding
>clustered index on (st.colfid, st.colkey, st.col1, st.col2). If you have
>SQL 2005, create the nonclustered on (st.col1, st.col2) with included
>columns on (st.colfid, st.colkey).
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...server/200605/1

indexes on foreign key columns?

I read recently in an ADO.NET book that I should create indexes on foreign
key constraints if they will commonly be used when joining. I can't
remember where, but I could swear that I had read somewhere else that
indexes were automatically created when you assign a foreign key constraint
to a column. What's the deal?
Joel Lyons
Hi Joel
You should create (yourself) indexes on referencing columns in a foreign key
constraint as it will improve things like the checking of the column when you
change a referenced value (for instance when you delete a row in the
referenced table). The referenced table will already have a primary key or a
unique index on the column being referenced.
John
"Joel Lyons" wrote:

> I read recently in an ADO.NET book that I should create indexes on foreign
> key constraints if they will commonly be used when joining. I can't
> remember where, but I could swear that I had read somewhere else that
> indexes were automatically created when you assign a foreign key constraint
> to a column. What's the deal?
> Joel Lyons
>
>
|||Hi Joel
Indexes are NOT automatically created on foreign keys, and it is usually a
good idea to create them. Even if you don't specifically write joins between
foreign and primary keys, if you ever allow deletes or updates to the
primary keys, SQL Server does an internal join to find matching FK values,
and an index can help the performance of the data modification.
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"Joel Lyons" <joell_REMOVE_@.novarad.net> wrote in message
news:eTWbqWyIIHA.1212@.TK2MSFTNGP05.phx.gbl...
>I read recently in an ADO.NET book that I should create indexes on foreign
> key constraints if they will commonly be used when joining. I can't
> remember where, but I could swear that I had read somewhere else that
> indexes were automatically created when you assign a foreign key
> constraint
> to a column. What's the deal?
> Joel Lyons
>

indexes on foreign key columns?

I read recently in an ADO.NET book that I should create indexes on foreign
key constraints if they will commonly be used when joining. I can't
remember where, but I could swear that I had read somewhere else that
indexes were automatically created when you assign a foreign key constraint
to a column. What's the deal?
Joel LyonsHi Joel
You should create (yourself) indexes on referencing columns in a foreign key
constraint as it will improve things like the checking of the column when yo
u
change a referenced value (for instance when you delete a row in the
referenced table). The referenced table will already have a primary key or a
unique index on the column being referenced.
John
"Joel Lyons" wrote:

> I read recently in an ADO.NET book that I should create indexes on foreign
> key constraints if they will commonly be used when joining. I can't
> remember where, but I could swear that I had read somewhere else that
> indexes were automatically created when you assign a foreign key constrain
t
> to a column. What's the deal?
> Joel Lyons
>
>|||Hi Joel
Indexes are NOT automatically created on foreign keys, and it is usually a
good idea to create them. Even if you don't specifically write joins between
foreign and primary keys, if you ever allow deletes or updates to the
primary keys, SQL Server does an internal join to find matching FK values,
and an index can help the performance of the data modification.
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"Joel Lyons" <joell_REMOVE_@.novarad.net> wrote in message
news:eTWbqWyIIHA.1212@.TK2MSFTNGP05.phx.gbl...
>I read recently in an ADO.NET book that I should create indexes on foreign
> key constraints if they will commonly be used when joining. I can't
> remember where, but I could swear that I had read somewhere else that
> indexes were automatically created when you assign a foreign key
> constraint
> to a column. What's the deal?
> Joel Lyons
>

indexes on foreign key columns?

I read recently in an ADO.NET book that I should create indexes on foreign
key constraints if they will commonly be used when joining. I can't
remember where, but I could swear that I had read somewhere else that
indexes were automatically created when you assign a foreign key constraint
to a column. What's the deal?
Joel LyonsHi Joel
You should create (yourself) indexes on referencing columns in a foreign key
constraint as it will improve things like the checking of the column when you
change a referenced value (for instance when you delete a row in the
referenced table). The referenced table will already have a primary key or a
unique index on the column being referenced.
John
"Joel Lyons" wrote:
> I read recently in an ADO.NET book that I should create indexes on foreign
> key constraints if they will commonly be used when joining. I can't
> remember where, but I could swear that I had read somewhere else that
> indexes were automatically created when you assign a foreign key constraint
> to a column. What's the deal?
> Joel Lyons
>
>|||Hi Joel
Indexes are NOT automatically created on foreign keys, and it is usually a
good idea to create them. Even if you don't specifically write joins between
foreign and primary keys, if you ever allow deletes or updates to the
primary keys, SQL Server does an internal join to find matching FK values,
and an index can help the performance of the data modification.
--
HTH
Kalen Delaney, SQL Server MVP
www.InsideSQLServer.com
http://sqlblog.com
"Joel Lyons" <joell_REMOVE_@.novarad.net> wrote in message
news:eTWbqWyIIHA.1212@.TK2MSFTNGP05.phx.gbl...
>I read recently in an ADO.NET book that I should create indexes on foreign
> key constraints if they will commonly be used when joining. I can't
> remember where, but I could swear that I had read somewhere else that
> indexes were automatically created when you assign a foreign key
> constraint
> to a column. What's the deal?
> Joel Lyons
>

Indexes on Bulk Insert data

Any help would be appreciated.

I am running a script that does the following in succession.

1-Drop existing database and create new database
2-Defines tables, stored procedures and functions in the database
3-Imports data using bulk insert
4-Analyzes data using stored procedures

I would like to improve the performance of the analysis in step 4 by
creating indexes in step 2.

Question 1-Are indexes updated when data is bulk inserted? I know they are
when using normal insert, update, or delete T-SQL but I am not sure about
bulk insert of data.

Question 2-Do I need to update the index statistics in any way or would they
be ready to use in step 4.

Thanks,
CJI would define step 4 as create indexes, that will have your stats up to
date and save you from any performance issues during the load or having
to reindex or update the stats

I would do the analysis in step five (depending what type of analysis)

HTH

Ray Higdon MCSE, MCDBA, CCNA

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Chris (chris@.hrn.org) writes:
> 1-Drop existing database and create new database
> 2-Defines tables, stored procedures and functions in the database
> 3-Imports data using bulk insert
> 4-Analyzes data using stored procedures
> I would like to improve the performance of the analysis in step 4 by
> creating indexes in step 2.
> Question 1-Are indexes updated when data is bulk inserted? I know they are
> when using normal insert, update, or delete T-SQL but I am not sure about
> bulk insert of data.

Yes, they are. However, you may prefer to wait with creating indexes until
you have loaded the data for best performance. You may also opt to create
clustered indexes before bulk-loading and add non-clustered indexes after.
This is particularly appealing if the order in the data files corre-
sponds to the clustered indexes.

> Question 2-Do I need to update the index statistics in any way or would
> they be ready to use in step 4.

If you create indexes after bulk-loading, SQL Server will create statistics
for you when creating the indexes.

If you create indexex before bulk-loading, the statistics will not be
correct after the load. Thus, it can be a good idea run UPDATE STATISTICS
in this situation. However, if you don't, SQL Server will auto-update
statistics, unless you have turned off this feature.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp