Showing posts with label table. Show all posts
Showing posts with label table. Show all posts

Tuesday, March 27, 2012

Advice on indexes

I have a table (detail) with 4 columns and over 30 million rows .
Say the columns are called ColA, ColB, ColC, ColD

ColA and ColB form a foreign key as this table is a 'detail' table for another master table in the database (master). The master table uses these two columns as its primary key.
To speed up joins between the two tables I have created an index over ColA and ColB

I frequently need to join the two tables together and so most of my queries are of the form:

SELECT master.*, detail.ColC, detail.ColD FROM master JOIN detail
ON master.ColA = detail.ColA and master.ColB = detail.ColB
WHERE master.ColA = @.valA
ORDER BY master.ColB, detail.ColC

This could return up to 60000 rows for a specific value of @.valA.
This is usually a sub-query that feeds directly into another query or a temporary table.

However, I also quite often need to filter the details further by ColC so I have queries like

SELECT master.*, detail.ColC, detail.ColD FROM master JOIN detail

ON master.ColA = detail.ColA and master.ColB = detail.ColB

WHERE master.ColA = @.valA AND detail.ColC = @.valC

ORDER BY master.ColB

The results set from this could be just a few hundred rows depending on @.valC

I clearly have a requirement to have an index across ColA, and ColB, presumably as the clustered index.

My question is how to speed up queries that involve ColC.
Do I create another index across ColA, ColB and ColC or just ColC by itself?
Will an index just on ColC make use of the the clustered index on the other columns?
Should I make the clustered index cover ColA, ColB and ColC instead ? etc ..

I am using SQL Express and am approaching the 4GB limit and this table and another one similar to it account for 96% of the database size.
The four columns in the detail table are all integer types and so don't take up much space per row. I am worried that a wide index will significantly add to the storage space per row and therefore significantly reduce the amount of data I can store in the database.

Any advice would be appreciated.

You defintely do not ever want to create one index that is a subset of another as you asked, ie. do not create two indexes on

ColA, ColB

ColA, ColB, ColC

The one on ColA, ColB, ColC does everything that the first one does, so it is all you need.

In your case it sounds like a clustered index on ColA, ColB, ColC should be all you need. Leaving out one column won't make much difference to the size. The size will be affected by the fillfactor and the fragmentation level of the index, so you should rebuild the index from time to time (how often depends on the nature of your updates) with a fillfactor of 100%, although a high fillfactor will increase the possibility that some updates will be slower.

|||Thanks for that.

I have done as you have said and created an index across all three columns and I am happy with both the speed of the queries and the size of the database.sql

Advice on ALTER TABLE statement.

Can I use an ALTEER TABLE statement in a stored procedure, I need to drop a
named constraint. Getting complie error.
ThanksTim Gains wrote:
> Can I use an ALTEER TABLE statement in a stored procedure, I need to
> drop a named constraint. Getting complie error.
>
> Thanks
You can use alter table from within a procedure (not sure why you woudl
want to). Maybe you're using dynamic sql and should be using either an
EXEC statement or sp_executesql. What is the reason for doing this from
a stored procedure (you can't inherit alter table rights with a
procedure grant on execute). It seems that if you're not using dynamic
sql for this in the procedure as some type of admin functionality (e.g.
to alter table ddl from your own procedure for admins), then you might
be better served by just executing the alter table as a batch without a
procedure. Can you explain why you need the procedure and post your
code?
David Gugick
Quest Software
www.imceda.com
www.quest.com

advice needed on synchronization of data

Hi
I need some advice on the best approach to solve the following problem:-
One important note: The data in the table is self referencing (hierarchical)
1. There will be a server running SQL server 2000 enterprise edition and
serveral lap tops that will be running MSDE
2. The laptops will be docked and querying against the server DB.
3. At some point the laptops will be undocked from the server and will be
taken out into the field.
- First the user will select certain records and then undock the laptop
- At this point the laptops MSDE DB is wiped and the selected records
will be inserted (parent and child records)
- The laptop is now running in undocked mode and queries will happen
against the local MSDE
4. Some time in the future the laptops will then be docked back to the
server
- Any new records in MSDE will be put into the server DB (parent and
child records)
- Any deleted records will be removed from the server DB (parent and
child records)
- Any updates will happen on the server DB (note that there may be some
user intervention to allow for choice of whether the update should happen or
not)
- Now the laptop will be docked and querying against the server DB
What is the best approach to solve this problem?
There is third party software such as
http://www.red-gate.com/sql/summary.htm
which looks promising has any one used such tools successfully for this
model?
Any help will be very much appreciatedHi
This sounds like merge replication could be an option, you may want to read
http://support.microsoft.com/defaul...b;en-us;Q324992
Note the licencing issue:
"MSDE 2000 does not require any licensing when you use it in a stand-alone
mode, but when you use it as part of a replication topology that involves
regular SQL Server editions, if the server is in Per Seat mode as opposed to
a Per Processor mode, each MSDE 2000 Subscriber must have a client-access
license (CAL)."
John
"Richard Wilde" wrote:

> Hi
> I need some advice on the best approach to solve the following problem:-
> One important note: The data in the table is self referencing (hierarchica
l)
> 1. There will be a server running SQL server 2000 enterprise edition and
> serveral lap tops that will be running MSDE
> 2. The laptops will be docked and querying against the server DB.
> 3. At some point the laptops will be undocked from the server and will be
> taken out into the field.
> - First the user will select certain records and then undock the lapto
p
> - At this point the laptops MSDE DB is wiped and the selected records
> will be inserted (parent and child records)
> - The laptop is now running in undocked mode and queries will happen
> against the local MSDE
> 4. Some time in the future the laptops will then be docked back to the
> server
> - Any new records in MSDE will be put into the server DB (parent and
> child records)
> - Any deleted records will be removed from the server DB (parent and
> child records)
> - Any updates will happen on the server DB (note that there may be som
e
> user intervention to allow for choice of whether the update should happen
or
> not)
> - Now the laptop will be docked and querying against the server DB
> What is the best approach to solve this problem?
> There is third party software such as
> http://www.red-gate.com/sql/summary.htm
> which looks promising has any one used such tools successfully for this
> model?
> Any help will be very much appreciated
>
>
>|||Thanks for that esp. for the licence issue
Has anyone out there used such tools as the one below to achieve similar
results?

Sunday, March 25, 2012

Advice Needed

I need to set up a table to define times when tasks will run. It needs to
allow for multiple times per day and if the task should run on the wends.
Once the task has run once for the specified service window for that time of
day I need to prevent the task from running again. I do not have a lot of
SQL experience and was wondering the best way to set up the table structure
might be. Any thoughts, examples or links would be greatly appreciated.
Thank you.>> I need to set up a table to define times when tasks will run. It needs t
o allow for multiple times per day and if the task should run on the wend
s. <<
CREATE TABLE TaskSchedule
(task_name CHAR(20) NOT NULL,
task_time DATETIME NOT NULL,
PRIMARY KEY (task_name, task_time),
.);
Just fill in the schedule for each task.
Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
events. What were you thinking about doing? We do not compute things
in SQL; we put them in tables and do joins.|||I'm wondering why you need a table. If the tasks are SQL Scripts, then just
run a scheduled DTS job or Store Procedure. You can create jobs to run at
the specific times and they would only run once. Plus you can have failure
emails if the job fails and will contact you.
"--CELKO--" wrote:

> CREATE TABLE TaskSchedule
> (task_name CHAR(20) NOT NULL,
> task_time DATETIME NOT NULL,
> PRIMARY KEY (task_name, task_time),
> ..);
> Just fill in the schedule for each task.
>
> Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
> events. What were you thinking about doing? We do not compute things
> in SQL; we put them in tables and do joins.
>|||Not sure myself becuase of my limited experience. I do know that I need the
ability to have my sproc run more then once in a day, possibly different
times on different days, and the ability to skip wends. Can I do all
this using a scheduled DTS job or sproc? Thank you.
"Darren" <Darren@.discussions.microsoft.com> wrote in message
news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...
> I'm wondering why you need a table. If the tasks are SQL Scripts, then
> just
> run a scheduled DTS job or Store Procedure. You can create jobs to run at
> the specific times and they would only run once. Plus you can have
> failure
> emails if the job fails and will contact you.
> "--CELKO--" wrote:
>|||Yes you can run the job except for the wends. In Enterprise Manager, go
to the Managment Folder, Expand SQL Server Agent, and you will see the jobs
section. Create a new job and in the Schedules tab create a new schedule an
d
you will see the options you can do. Good luck.
Darren
"Code Boy" wrote:

> Not sure myself becuase of my limited experience. I do know that I need t
he
> ability to have my sproc run more then once in a day, possibly different
> times on different days, and the ability to skip wends. Can I do all
> this using a scheduled DTS job or sproc? Thank you.
>
> "Darren" <Darren@.discussions.microsoft.com> wrote in message
> news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...
>
>sql

Advice Needed

I need to set up a table to define times when tasks will run. It needs to
allow for multiple times per day and if the task should run on the weekends.
Once the task has run once for the specified service window for that time of
day I need to prevent the task from running again. I do not have a lot of
SQL experience and was wondering the best way to set up the table structure
might be. Any thoughts, examples or links would be greatly appreciated.
Thank you.
>> I need to set up a table to define times when tasks will run. It needs to allow for multiple times per day and if the task should run on the weekends. <<
CREATE TABLE TaskSchedule
(task_name CHAR(20) NOT NULL,
task_time DATETIME NOT NULL,
PRIMARY KEY (task_name, task_time),
..);
Just fill in the schedule for each task.
[vbcol=seagreen]
Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
events. What were you thinking about doing? We do not compute things
in SQL; we put them in tables and do joins.
|||I'm wondering why you need a table. If the tasks are SQL Scripts, then just
run a scheduled DTS job or Store Procedure. You can create jobs to run at
the specific times and they would only run once. Plus you can have failure
emails if the job fails and will contact you.
"--CELKO--" wrote:

> CREATE TABLE TaskSchedule
> (task_name CHAR(20) NOT NULL,
> task_time DATETIME NOT NULL,
> PRIMARY KEY (task_name, task_time),
> ..);
> Just fill in the schedule for each task.
>
> Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
> events. What were you thinking about doing? We do not compute things
> in SQL; we put them in tables and do joins.
>
|||Not sure myself becuase of my limited experience. I do know that I need the
ability to have my sproc run more then once in a day, possibly different
times on different days, and the ability to skip weekends. Can I do all
this using a scheduled DTS job or sproc? Thank you.
"Darren" <Darren@.discussions.microsoft.com> wrote in message
news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...[vbcol=seagreen]
> I'm wondering why you need a table. If the tasks are SQL Scripts, then
> just
> run a scheduled DTS job or Store Procedure. You can create jobs to run at
> the specific times and they would only run once. Plus you can have
> failure
> emails if the job fails and will contact you.
> "--CELKO--" wrote:
|||Yes you can run the job except for the weekends. In Enterprise Manager, go
to the Managment Folder, Expand SQL Server Agent, and you will see the jobs
section. Create a new job and in the Schedules tab create a new schedule and
you will see the options you can do. Good luck.
Darren
"Code Boy" wrote:

> Not sure myself becuase of my limited experience. I do know that I need the
> ability to have my sproc run more then once in a day, possibly different
> times on different days, and the ability to skip weekends. Can I do all
> this using a scheduled DTS job or sproc? Thank you.
>
> "Darren" <Darren@.discussions.microsoft.com> wrote in message
> news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...
>
>

Advice Needed

I need to set up a table to define times when tasks will run. It needs to
allow for multiple times per day and if the task should run on the weekends.
Once the task has run once for the specified service window for that time of
day I need to prevent the task from running again. I do not have a lot of
SQL experience and was wondering the best way to set up the table structure
might be. Any thoughts, examples or links would be greatly appreciated.
Thank you.>> I need to set up a table to define times when tasks will run. It needs t
o allow for multiple times per day and if the task should run on the weekend
s. <<
CREATE TABLE TaskSchedule
(task_name CHAR(20) NOT NULL,
task_time DATETIME NOT NULL,
PRIMARY KEY (task_name, task_time),
.);
Just fill in the schedule for each task.
[vbcol=seagreen]
Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
events. What were you thinking about doing? We do not compute things
in SQL; we put them in tables and do joins.|||I'm wondering why you need a table. If the tasks are SQL Scripts, then just
run a scheduled DTS job or Store Procedure. You can create jobs to run at
the specific times and they would only run once. Plus you can have failure
emails if the job fails and will contact you.
"--CELKO--" wrote:

> CREATE TABLE TaskSchedule
> (task_name CHAR(20) NOT NULL,
> task_time DATETIME NOT NULL,
> PRIMARY KEY (task_name, task_time),
> ..);
> Just fill in the schedule for each task.
>
> Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
> events. What were you thinking about doing? We do not compute things
> in SQL; we put them in tables and do joins.
>|||Not sure myself becuase of my limited experience. I do know that I need the
ability to have my sproc run more then once in a day, possibly different
times on different days, and the ability to skip weekends. Can I do all
this using a scheduled DTS job or sproc? Thank you.
"Darren" <Darren@.discussions.microsoft.com> wrote in message
news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...[vbcol=seagreen]
> I'm wondering why you need a table. If the tasks are SQL Scripts, then
> just
> run a scheduled DTS job or Store Procedure. You can create jobs to run at
> the specific times and they would only run once. Plus you can have
> failure
> emails if the job fails and will contact you.
> "--CELKO--" wrote:
>|||Yes you can run the job except for the weekends. In Enterprise Manager, go
to the Managment Folder, Expand SQL Server Agent, and you will see the jobs
section. Create a new job and in the Schedules tab create a new schedule an
d
you will see the options you can do. Good luck.
Darren
"Code Boy" wrote:

> Not sure myself becuase of my limited experience. I do know that I need t
he
> ability to have my sproc run more then once in a day, possibly different
> times on different days, and the ability to skip weekends. Can I do all
> this using a scheduled DTS job or sproc? Thank you.
>
> "Darren" <Darren@.discussions.microsoft.com> wrote in message
> news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...
>
>

Advice Needed

I need to set up a table to define times when tasks will run. It needs to
allow for multiple times per day and if the task should run on the weekends.
Once the task has run once for the specified service window for that time of
day I need to prevent the task from running again. I do not have a lot of
SQL experience and was wondering the best way to set up the table structure
might be. Any thoughts, examples or links would be greatly appreciated.
Thank you.>> I need to set up a table to define times when tasks will run. It needs to allow for multiple times per day and if the task should run on the weekends. <<
CREATE TABLE TaskSchedule
(task_name CHAR(20) NOT NULL,
task_time DATETIME NOT NULL,
PRIMARY KEY (task_name, task_time),
..);
Just fill in the schedule for each task.
>> Once the task has run once for the specified service window for that time of day I need to prevent the task from running again. <<
Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
events. What were you thinking about doing? We do not compute things
in SQL; we put them in tables and do joins.|||I'm wondering why you need a table. If the tasks are SQL Scripts, then just
run a scheduled DTS job or Store Procedure. You can create jobs to run at
the specific times and they would only run once. Plus you can have failure
emails if the job fails and will contact you.
"--CELKO--" wrote:
> >> I need to set up a table to define times when tasks will run. It needs to allow for multiple times per day and if the task should run on the weekends. <<
> CREATE TABLE TaskSchedule
> (task_name CHAR(20) NOT NULL,
> task_time DATETIME NOT NULL,
> PRIMARY KEY (task_name, task_time),
> ..);
> Just fill in the schedule for each task.
> >> Once the task has run once for the specified service window for that time of day I need to prevent the task from running again. <<
> Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
> events. What were you thinking about doing? We do not compute things
> in SQL; we put them in tables and do joins.
>|||Not sure myself becuase of my limited experience. I do know that I need the
ability to have my sproc run more then once in a day, possibly different
times on different days, and the ability to skip weekends. Can I do all
this using a scheduled DTS job or sproc? Thank you.
"Darren" <Darren@.discussions.microsoft.com> wrote in message
news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...
> I'm wondering why you need a table. If the tasks are SQL Scripts, then
> just
> run a scheduled DTS job or Store Procedure. You can create jobs to run at
> the specific times and they would only run once. Plus you can have
> failure
> emails if the job fails and will contact you.
> "--CELKO--" wrote:
>> >> I need to set up a table to define times when tasks will run. It
>> >> needs to allow for multiple times per day and if the task should run
>> >> on the weekends. <<
>> CREATE TABLE TaskSchedule
>> (task_name CHAR(20) NOT NULL,
>> task_time DATETIME NOT NULL,
>> PRIMARY KEY (task_name, task_time),
>> ..);
>> Just fill in the schedule for each task.
>> >> Once the task has run once for the specified service window for that
>> >> time of day I need to prevent the task from running again. <<
>> Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
>> events. What were you thinking about doing? We do not compute things
>> in SQL; we put them in tables and do joins.
>>|||Yes you can run the job except for the weekends. In Enterprise Manager, go
to the Managment Folder, Expand SQL Server Agent, and you will see the jobs
section. Create a new job and in the Schedules tab create a new schedule and
you will see the options you can do. Good luck.
Darren
"Code Boy" wrote:
> Not sure myself becuase of my limited experience. I do know that I need the
> ability to have my sproc run more then once in a day, possibly different
> times on different days, and the ability to skip weekends. Can I do all
> this using a scheduled DTS job or sproc? Thank you.
>
> "Darren" <Darren@.discussions.microsoft.com> wrote in message
> news:9AE28789-D43D-422F-B185-D682C5BF289A@.microsoft.com...
> > I'm wondering why you need a table. If the tasks are SQL Scripts, then
> > just
> > run a scheduled DTS job or Store Procedure. You can create jobs to run at
> > the specific times and they would only run once. Plus you can have
> > failure
> > emails if the job fails and will contact you.
> >
> > "--CELKO--" wrote:
> >
> >> >> I need to set up a table to define times when tasks will run. It
> >> >> needs to allow for multiple times per day and if the task should run
> >> >> on the weekends. <<
> >>
> >> CREATE TABLE TaskSchedule
> >> (task_name CHAR(20) NOT NULL,
> >> task_time DATETIME NOT NULL,
> >> PRIMARY KEY (task_name, task_time),
> >> ..);
> >>
> >> Just fill in the schedule for each task.
> >>
> >> >> Once the task has run once for the specified service window for that
> >> >> time of day I need to prevent the task from running again. <<
> >>
> >> Use a query with "task_time >= CURRENT_TIMESTAMP" so you ignore past
> >> events. What were you thinking about doing? We do not compute things
> >> in SQL; we put them in tables and do joins.
> >>
> >>
>
>sql

Advice badly needed

I have just been given a ridiculous task... There is an existing SQL database that has one table with two fields. The first is an ID column, the second has information that I somehow need to retrieve. This is my dilemma. Here's something like how the ROWS look in this table:
__________________________________________________ ______________
PRACTICE: Practice 1 COMPLETE HISTORY REPORT PAGE:
DATE: AUG 18, 1973 TIME: 9:04:36
NULL
NULL
12-53-48 DOE JOHN BALANCE: .00
123 Street DR
Somewhere ST 12345

DATE DR PROC.. MD DIAG.. DESCRIPTION........... TRN.AMOUNT TR.BALAN
NULL
JOHN DOE
08/12/94 13 73630 1 959.7 FOOT-COMPLETE 3+ VIEWS 23.35 .00
08/23/94 13 *INS. FILED WITH TRAVELERS
08/29/94 13 39 PAYMENT - WORKER'S COMP. -23.35 .00
TOTAL DUE: .00
__________________________________________________ ______________

Each line is a seperate row in the table!?! Also, the lines with the dates, near the bottom, can have different numbers of rows (Sometimes several, sometimes hundreds) I don't know how this data was imported. It appears that I have 122000 accounts but they are spread across 3.5 million rows... I need to devise some way to take this data out.. Can anyone please give some advice??I'm having trouble understanding your explaination. Can you post the assignment as the instructor gave it to you?

-PatP|||Basically I've been asked to create an Intranet ASP.Net reporting feature for this data. I have to be able to split up this information into some sort of normalized relational structure. I need to be able to grab the start of each record (IE the practice Name row) then each row within this collection of rows. All of this data is in one column! there is no structure to it, as of now. I want to be able to seperate each account into other tables to give some structure... does that make sense?|||So you just have this text blob sitting all by its lonesome in a row, as though somebody dumped a chunk of XML in there? No database enforced schema at all?

Bleach!

-PatP|||I wish it was in one row...

Row 1: PRACTICE: Practice 1 COMPLETE HISTORY REPORT PAGE:
Row 2: DATE: AUG 18, 1973 TIME: 9:04:36
Row 3: NULL

See what I mean?! This is one field, one table.|||If at first you don't succeed, apply brute force. Cursor through the monstrosity, and make a structured schema from it. If worst comes to worst, plop the parts into a work table with pure character columns, then slice and dice them as needed.

What you've got now is a fiasco in the making. YOu have to enforce some structure onto it, soon!

-PatP|||Yes, structure has to be made of this. There are no updates being made to it. It is an old archive that someone imported from an Oracle DB from our pre-merger and it's just sitting there, needing connectivity for reporting. I had hoped to be able to do some types of nested queries to extract what I needed, adding them to another set of tables as I went. Mostly what I know about cursors are that I hate them and can't ever seem to get them to work correctly. As for making the structured schema from it.. would you be able to possibly point me towards any documentation on accomplishing that? Your answer seemed to be a bit above my head:)|||can't you use "text to columns" in excel and use <space> as the delimeter

or write a macro to do repeated keystrokes to structure the data as someone suggested previously|||The exact process varies a little bit, depending on what tools you are using to process your data heaps (the unstructured tables).

Hopefully you know how to interpret the heap. In other words there are either a fixed number of rows for each logical group, or there is some kind of "marker" that will show you where one group ends and another group begins. I assume that the sequence of the rows is fixed (they stay in the same order) and significant (that the order matters). Once you understand the structure of your heap, then you can start to make better sense of it.

You basically want to write some kind of loop that will process each group of related pieces of text (rows within your heap), and put them into a table with more meaningful rows and columns (probably one column for each row in the heap, unless some of them are useless and/or missing).

Without understanding exactly what you've got, I can't think of a way to come up with anything like a step-by-step solution. You'll have to find someone that understands the data to help you structure it.

-PatP|||Ok, from trying to work with this via TSQL using cursors, I've found too many potential errors caused by inconsistency of the original data input. I've now created a VB.Net Windows application to handle the data collection/transformation which encapsulates the transformed accounts into a class before attempting to insert into the new normalized relational database via stored procedure.

I have one question (for now) about form refreshing. The form that allows the user to begin the transformation counts the actual accounts to be worked, placing that number into a label. As each record is completed, I cast back to the form, reducing a label for accounts remaining and increasing a label for accounts complete, then refresh the form to reflect the changes. This process occurs rather quickly but seems to make an odd visual effect to the forms groupbox and listbox controls. They seem to shake as the transformation thread is working. Now, this application is really only to be used once, but I would like to know if this visual effect can be prevented when developing future reusable projects.|||Yes, it can, but I don't have an easy reference available. Maybe someone else has code or a URL they can post. If not, remind me next week and I'll find one for you.

-PatP|||Thanks Pat!

Advice

Hi,
Nightly I am importing 8000 rows of data into a table with 3 billion rows.
The table has one clustered index. Should I disable the clustered index
before importing? If so where do I find info on disabling and enabling
clustered index on a column?
ThanksYou can't "disable" a clustered index, you would have to drop it and
recreate it. And doing that would be very costly with 3 billion rows. So,
you do not want to do that.
Tom
"Chris" <Chris@.discussions.microsoft.com> wrote in message
news:85B9A949-CDC1-410C-90C3-CC3502C055D3@.microsoft.com...
> Hi,
> Nightly I am importing 8000 rows of data into a table with 3 billion rows.
> The table has one clustered index. Should I disable the clustered index
> before importing? If so where do I find info on disabling and enabling
> clustered index on a column?
> Thanks

AdventureWorksDW

I am using a tutorial to learn SQL Reporting services and it calls for a
table vResellers in AdventureWorksDW database. I don't have this database,
instead I have AdventureWorks2000. Can anyone tell me where I can get
AdventureWorksDW?
Thanks,Hi,
The SQL Server 2005 Samlple database can be downloaded from Microsoft. Try
following link
http://www.microsoft.com/downloads/details.aspx?FamilyId=E719ECF7-9F46-4312-AF89-6AD8702E4E6E&displaylang=en
Patrick
"Moses" <Moses@.discussions.microsoft.com> wrote in message
news:755330A4-335B-4A31-A6ED-CFF217525F03@.microsoft.com...
>I am using a tutorial to learn SQL Reporting services and it calls for a
> table vResellers in AdventureWorksDW database. I don't have this database,
> instead I have AdventureWorks2000. Can anyone tell me where I can get
> AdventureWorksDW?
> Thanks,|||Patrick,
I tried installing this but I cannot attach the database. I believe it is
because this is a for sql 2005. Is there a sql 2000 version?
"Patrick" wrote:
> Hi,
> The SQL Server 2005 Samlple database can be downloaded from Microsoft. Try
> following link
> http://www.microsoft.com/downloads/details.aspx?FamilyId=E719ECF7-9F46-4312-AF89-6AD8702E4E6E&displaylang=en
> Patrick
> "Moses" <Moses@.discussions.microsoft.com> wrote in message
> news:755330A4-335B-4A31-A6ED-CFF217525F03@.microsoft.com...
> >I am using a tutorial to learn SQL Reporting services and it calls for a
> > table vResellers in AdventureWorksDW database. I don't have this database,
> > instead I have AdventureWorks2000. Can anyone tell me where I can get
> > AdventureWorksDW?
> >
> > Thanks,
>
>|||when you download thecourse fromthe course: 2030a Creating Reporting
Solutions Using Microsoft SQL Server 2000 Reporting Services in
c:\Program Files\Microsoft Learning\2030\Setup\Database
you find it
but my probleme is
I can't find database "AdventureWorks2000" in 2030a Creating Reporting
Solutions Using Microsoft SQL Server 2000 Reporting Services
IF YOU HAVE database "AdventureWorks2000"
SEND IT TO ME AND I SEND YOU
AdventureWorksDW database

AdventureWorks\AdventureWorksDW question

I thought that all data in AdventureWorksDW came from the OLTP AdventureWorks database. But....then I looked at DimTime table in "DW". I doubt that level of detail exists in the OLTP database.

Is it common to add new data and fields to the OLAP side that didn't exist in the OLTP side?

Pup

Dear barkingpup,

Can you plz give more details about you question ?

OLAP create time dimension based on the_date column of time dimension table, you have to select which time heirarchy you want.

|||

Hello Syed Mahmood Ali,

i think that barkingpup talked about the data in the AdventureWorks and the AdventureWorksDW. He think that AdventureWorksDW is a data mart(data warehouse) created from the AdventureWorks database which would be the OLTP. And his question is, if its the case, is it usual to add data in the data mart which are not in the OLTP. According to me, in the data mart, the data come from only the OLTP. Perhaps from different database but which set up the OLTP system. AdventureWorksDW is only an sample and the conception is quite different than AdventureWorks. So the needed data for the sample are differents too...

I hope that will answer the barkingpup's question.

|||i also gone throug adventuerwork and adventuerworkdw still doubt are adventuerwork is the only source for adventuerworkdw can anybody guide me for creating diagram for complet adventuerwokrdw datamart.|||

Hello. You build the Time dimension in SSIS(Integration Services) or in the Data Source View(by a named calculation) using TSQL Date functions on the Order or Invoice Date in the OLTP database.

One of the most useful us the TSQL Datepart function where you can derive month, quarters and years from a date column.

You will only need a single date column to build an entire time dimension.

HTH

Thomas Ivarsson

Thursday, March 22, 2012

AdventureWorks\AdventureWorksDW question

I thought that all data in AdventureWorksDW came from the OLTP AdventureWorks database. But....then I looked at DimTime table in "DW". I doubt that level of detail exists in the OLTP database.

Is it common to add new data and fields to the OLAP side that didn't exist in the OLTP side?

Pup

Dear barkingpup,

Can you plz give more details about you question ?

OLAP create time dimension based on the_date column of time dimension table, you have to select which time heirarchy you want.

|||

Hello Syed Mahmood Ali,

i think that barkingpup talked about the data in the AdventureWorks and the AdventureWorksDW. He think that AdventureWorksDW is a data mart(data warehouse) created from the AdventureWorks database which would be the OLTP. And his question is, if its the case, is it usual to add data in the data mart which are not in the OLTP. According to me, in the data mart, the data come from only the OLTP. Perhaps from different database but which set up the OLTP system. AdventureWorksDW is only an sample and the conception is quite different than AdventureWorks. So the needed data for the sample are differents too...

I hope that will answer the barkingpup's question.

|||i also gone throug adventuerwork and adventuerworkdw still doubt are adventuerwork is the only source for adventuerworkdw can anybody guide me for creating diagram for complet adventuerwokrdw datamart.|||

Hello. You build the Time dimension in SSIS(Integration Services) or in the Data Source View(by a named calculation) using TSQL Date functions on the Order or Invoice Date in the OLTP database.

One of the most useful us the TSQL Datepart function where you can derive month, quarters and years from a date column.

You will only need a single date column to build an entire time dimension.

HTH

Thomas Ivarsson

AdventureWorks\AdventureWorksDW question

I thought that all data in AdventureWorksDW came from the OLTP AdventureWorks database. But....then I looked at DimTime table in "DW". I doubt that level of detail exists in the OLTP database.

Is it common to add new data and fields to the OLAP side that didn't exist in the OLTP side?

Pup

Dear barkingpup,

Can you plz give more details about you question ?

OLAP create time dimension based on the_date column of time dimension table, you have to select which time heirarchy you want.

|||

Hello Syed Mahmood Ali,

i think that barkingpup talked about the data in the AdventureWorks and the AdventureWorksDW. He think that AdventureWorksDW is a data mart(data warehouse) created from the AdventureWorks database which would be the OLTP. And his question is, if its the case, is it usual to add data in the data mart which are not in the OLTP. According to me, in the data mart, the data come from only the OLTP. Perhaps from different database but which set up the OLTP system. AdventureWorksDW is only an sample and the conception is quite different than AdventureWorks. So the needed data for the sample are differents too...

I hope that will answer the barkingpup's question.

|||i also gone throug adventuerwork and adventuerworkdw still doubt are adventuerwork is the only source for adventuerworkdw can anybody guide me for creating diagram for complet adventuerwokrdw datamart.|||

Hello. You build the Time dimension in SSIS(Integration Services) or in the Data Source View(by a named calculation) using TSQL Date functions on the Order or Invoice Date in the OLTP database.

One of the most useful us the TSQL Datepart function where you can derive month, quarters and years from a date column.

You will only need a single date column to build an entire time dimension.

HTH

Thomas Ivarsson

AdventureWorks in vwd

Goodday all

I wonder if anyone can help.

I'm trying to work through a tutorial using a sample database , Adventureworks. When I drag a table "Address" onto my page to set up a grid veiw , and start debugging , the error message reads "invalid object name Address"

On the database explorer the table has (Person) next to the name Address. This I think has something to do with the schema. I cannot get it right to change anything , no matter what I try. I have used this data base in a windows application and it works fine. No (Person ) attached to the table name.

Has anyone got any ideas.

Thanks

Rob

That is a known issue.

One workaround is to edit the ASP.Net code in the SQL Datasource similar to this:

 <asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:AdventureWorksConnectionString%>" DeleteCommand="DELETE FROM[Person.Address] WHERE [AddressID] = @.AddressID" InsertCommand="INSERT INTO [Person.Address] ([AddressLine1], [AddressLine2], [City], [StateProvinceID], [PostalCode], [rowguid], [ModifiedDate]) VALUES (@.AddressLine1, @.AddressLine2, @.City, @.StateProvinceID, @.PostalCode, @.rowguid, @.ModifiedDate)" SelectCommand="SELECT * FROMPerson.Address" UpdateCommand="UPDATE [Person.Address] SET [AddressLine1] = @.AddressLine1, [AddressLine2] = @.AddressLine2, [City] = @.City, [StateProvinceID] = @.StateProvinceID, [PostalCode] = @.PostalCode, [rowguid] = @.rowguid, [ModifiedDate] = @.ModifiedDate WHERE [AddressID] = @.AddressID">

You can also open up the Configure Datasource window and select "Specify a custom SQL Statement..." instead of a table and edit the text there.

You must also refresh the schema of the Gridview. If that doesn't work, delete the GridView, add another one and connect it to the Datasource you just edited.

|||

Thanks for that . I,v nearly got it to work . I can at least see the data now. However I cannot edit the data or work with it . When I try I get this error message.

Implicit conversion from data type sql_variant to uniqueidentifier is not allowed. Use the CONVERT function to run this query.

How can I get around this?

Regards

Rob

|||

Without seeing the code it's hard to say.

Tuesday, March 20, 2012

Advantages?

I would welcome opinions on whether FTS would help in our scenario.
The table has about 28 million rows and has about 10,000 rows added every
morning in an intensive batch process. Then another batch query process is
run that looks for partial name matches.
Eight of the fields we query against are char or varchar, all with single
words.
Sample query: SELECT casenumber FROM table WHERE fname LIKE 'j%' AND lname
LIKE 'smi%'. Rreturns 55,874 rows in 7 seconds in QA.
I am also concerned about time to populate FT index every day.
Machine is dual Xeon 3.2 with 4GB ram, OS on RAID1 & SQL data on RAID5. Win
2003 Server and SQL2000, with SQL2005 later this year.
Thanks much!
Wow! That's fantastic speed for a like. I'd try change tracking. IIRC on a
similar machine I was able to hit 2000 rows per minute with SQL 2000.
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
"Bil Click" <BilClick@.discussions.microsoft.com> wrote in message
news:FFF888F6-8310-4B1F-83B0-399830C17F53@.microsoft.com...
>I would welcome opinions on whether FTS would help in our scenario.
> The table has about 28 million rows and has about 10,000 rows added every
> morning in an intensive batch process. Then another batch query process is
> run that looks for partial name matches.
> Eight of the fields we query against are char or varchar, all with single
> words.
> Sample query: SELECT casenumber FROM table WHERE fname LIKE 'j%' AND lname
> LIKE 'smi%'. Rreturns 55,874 rows in 7 seconds in QA.
> I am also concerned about time to populate FT index every day.
> Machine is dual Xeon 3.2 with 4GB ram, OS on RAID1 & SQL data on RAID5.
> Win
> 2003 Server and SQL2000, with SQL2005 later this year.
> Thanks much!
|||Thanks Hilary, but do you think a Full Text search would be faster searching
on single words?
"Hilary Cotter" wrote:

> Wow! That's fantastic speed for a like. I'd try change tracking. IIRC on a
> similar machine I was able to hit 2000 rows per minute with SQL 2000.
> --
> 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
> "Bil Click" <BilClick@.discussions.microsoft.com> wrote in message
> news:FFF888F6-8310-4B1F-83B0-399830C17F53@.microsoft.com...
>
>
|||It will be for larger tables. I am not sure where the cut off it - i.e.
20,000 rows or 2 million.
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
"Bil Click" <BilClick@.discussions.microsoft.com> wrote in message
news:FDFBA954-00ED-4444-A7EF-2B5547510343@.microsoft.com...[vbcol=seagreen]
> Thanks Hilary, but do you think a Full Text search would be faster
> searching
> on single words?
> "Hilary Cotter" wrote:

Advantages of using nonclustered index after using clustered index on one table

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 ?

Thanks

Yes, you are correct. A nonclustered index like an index in a book "points" to a particular record which makes them ideal for exact matches queries. A NCI will either point to a rowid in a heap situation or the key in a CI-based table.

BOL 2005 excerpt:

If the underlying table is sorted using a clustered index, the location is the clustering key value; otherwise, the location is the row ID (RID) comprised of the file number, page number, and slot number of the row

HTH,

Derek

|||

see more info on the other post

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=522859&SiteID=1

creation of Clustered index must happen first because

if NCIs are created first. The creation of a clustered index later will

force the recreation of all the NCIs to force it to use CI's rather than RID as locator

thereby causing a lot of trouble in the database.

|||

It is not entirely accurate that rows are sorted and stored in a clustered index. The b-tree structure ensures logical ordering of the rows and physically the rows may not be sorted in the same manner or present next to one another in a page for example. Please take a look at the link below for series of BOL topics on indexes:

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

Advantages of Table variables over Temp tables

What are the advantages of using a table type variables over a
temporary table. Isn't the data stored in the temp db in the case of
table type variables? if not, where is the data stored?An article on this here:
http://www.aspfaq.com/show.asp?id=2475
David Portas
SQL Server MVP
--|||You can read following article written by Mike Gunderloy, describing
usage and advantages with respect to Table variable and temporary
tables.
<http://developer.com/db/article.php/10920_3414331_1>
-Hari Sharma
India|||http://toponewithties.blogspot.com/...nd.h
tml
Roji. P. Thomas
Net Asset Management
http://toponewithties.blogspot.com
<balacr@.gmail.com> wrote in message
news:1127109967.631131.113870@.g14g2000cwa.googlegroups.com...
> What are the advantages of using a table type variables over a
> temporary table. Isn't the data stored in the temp db in the case of
> table type variables? if not, where is the data stored?
>

Monday, March 19, 2012

Advantage of Temp Table

When I import data I first import it from a text file into a table of
it's own, then using some logic insert some of the records into a
permanent table.

I am considering having the table that the data from the text file is
placed in being there all the time and just clearing it out after I do
the import, or creating it and after using it then drop it, or using a
temporary table.

What are the advantages of a temporary table as opposed to creating a
regular table and dropping it after use?Not much difference between a temp table and permenant table. Security,
automatic distruction, and one or the other may faster depending on the
disk/file layout. I would ask why not just push it directly into the
destination? Also if the text is coming from another SQL available source,
why not skip both the text file and the temporary table?

It also may be faster depending on need for availability, space, and
indexing to create a new table and do select into based on a union all of
the two tables. Then rename the table.

<shumaker@.cs.fsu.edu> wrote in message
news:1114111315.338927.231880@.g14g2000cwa.googlegr oups.com...
> When I import data I first import it from a text file into a table of
> it's own, then using some logic insert some of the records into a
> permanent table.
> I am considering having the table that the data from the text file is
> placed in being there all the time and just clearing it out after I do
> the import, or creating it and after using it then drop it, or using a
> temporary table.
> What are the advantages of a temporary table as opposed to creating a
> regular table and dropping it after use?|||Thanks.

"I would ask why not just push it directly into the
destination?"

Because I have to do some logic based on what is not in the imported
data. If a certain record exists in my table, but not in the data
being imported, then I need to modify some flags in the existing
record. So I import into an empty table, and do updates "if not in"
imported table then update my existing table.|||>> What are the advantages of a temporary table as opposed to creating
a regular table and dropping it after use? <<

A regular table will port, can have constraints, DRI actions, etc. But
do not drop it after use; just clean it out before and after you load
the data for scrubbing.

Advanced SQL HELP: transform rows to columns

I have a table of 1000+ rows with 100+ different items with each Id having max 10 items

Id item
1 a
1 b
2 c
2 a
2 d
3 b
3 z

each item has an order in a different lookup table
item item_seq
a 1
b 2
c 3
d 4

The item columns (below) need to use the item order from lookup table, so the output table is as follows

Id item item2 item3
1 a b
2 a c d
3 b z

PLEASE HELP !!!Hello,
I am a little bit confused about your target but what I can catch is that you are asking how to make an output table like the one you demonstrated at the end. If it is so, I think that the table design itself is not correct and what you need is to make a one to many relation ship table composed of 2 fields that looks like the following

Id Item
1 a
1 b
2 a
2 c
2 d
3 b
3 Z
and so on

and by this way you can insert as many as items as you like with each Id

Thanks|||Thanks vm for replying Rasha.

To make matters simpler, I exclude the item order table since I found a way of doing that.
So basically the input table is
Id Item
1 a
1 b
2 a
2 c
2 d
3 b
3 Z

and the output table I need to come up with should be like

Id Item1 Item2 Item3
1 a b
2 a c d
3 b z

The CASE statement is diffucilt to use since there are 100+ different items (and new ones are added all the time) and each id can have 1 to 9 items, so columns Item1 to Item9 per id are needed.

Any ideas ?

Originally posted by rasha
Hello,
I am a little bit confused about your target but what I can catch is that you are asking how to make an output table like the one you demonstrated at the end. If it is so, I think that the table design itself is not correct and what you need is to make a one to many relation ship table composed of 2 fields that looks like the following

Id Item
1 a
1 b
2 a
2 c
2 d
3 b
3 Z
and so on

and by this way you can insert as many as items as you like with each Id

Thanks|||What you are asking for is called a cross tab query. The pivot is best handled on the client if at all possible, but it can also be done in SQL when you can't do it on the client.

-PatP|||Hi, I do not know much about Cross tab query but I think the following dissccusion may help you:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=19008|||Assuming that your item values are sortable for each id (that there aren't any NULL values and no duplicates), you can use:CREATE TABLE dbo.table00 (
id INT NOT NULL
, item CHAR(1) NOT NULL
)

INSERT INTO dbo.table00 (id, item)
SELECT 1, 'a'
UNION ALL SELECT 1, 'b'
UNION ALL SELECT 2, 'a'
UNION ALL SELECT 2, 'c'
UNION ALL SELECT 2, 'd'
UNION ALL SELECT 3, 'b'
UNION ALL SELECT 3, 'z'

SELECT a.id, Min(a.item)
+ Coalesce(', ' + Min(b.item), '')
+ Coalesce(', ' + Min(c.item), '')
FROM dbo.table00 AS a
LEFT JOIN dbo.table00 AS b
ON (b.id = a.id
AND a.item < b.item)
LEFT JOIN dbo.table00 AS c
ON (c.id = a.id
AND b.item < c.item)
GROUP BY a.id
ORDER BY a.id

DROP TABLE dbo.table00-PatP|||Thanks very much for your reply PAT.

I have to say your approach with the LEFT join and item> comparisons
is simple and clever.
However bearing in mind that there are 100+ different items, doing 100+ left joins...I don't how efficient will that be...
Thanks very much anyway.|||Originally posted by dim2000
However bearing in mind that there are 100+ different items, doing 100+ left joins...I don't how efficient will that be... Try it. You might be shocked (I know that I was).

A cross tab is still better handled on the client when that is possible, but the server does a better job than I thought that it would.

-PatP|||Thanks for your reply Pat.

The left joins worked quite fast actually, on the server that is not the client.

Do you know if I could use the Case or ISNULL statements for this.

e.g. CASE when item='a' THEN item1 ELSE 'None' END AS 'MCQ Raw',

I used the case statement before but only for amounts that needed to be summed up, when I tried to use it with text fields I could not get it to work,
Any ideas?

Advanced SELECT for a newbie

I have a table full of Latitudes, Longitudes, address, customername, etc. , I need to grab some input(Latitude, Longitude, range) from the user. So now I have a source lat, long(user) and destination lat, long(rows in dbase). I need to take the 2 points and compute a distance from the user given lat, long to every lat, long in the database and check that distance againt the range given from the user. If the distance is below the range, I need to put that row into a temp table and return the temp table at the end of the stored proc.

As of right now I am completely lost and need some guidance.

I would also like to be able to add the computed distance to a table. Here is the function and stored procedure i have so far...

ALTER PROCEDURE [dbo].[sp_getDistance]

@.srcLat numeric(18,6),
@.srcLong numeric(18,6),
@.range int
AS
BEGIN
SET NOCOUNT ON;

SELECT * FROM dbo.PL_CustomerGeoCode cg
WHERE dbo.fn_computeDistance(@.srcLat, cg.geocodeLat, @.srcLong, cg.geocodeLong) < @.range

END

CREATE FUNCTION fn_computeDistance
(
-- Add the parameters for the function here
@.lat1 numeric(18,6),
@.lat2 numeric(18,6),
@.long1 numeric(18,6),
@.long2 numeric(18,6)
)
RETURNS numeric(18,6)
AS
BEGIN
-- Declare the return variable here
DECLARE @.dist numeric(18,6)

IF ((@.lat1 = @.lat2) AND (@.long1 = @.long2))
SELECT @.dist = 0.0
ELSE
IF (((sin(@.lat1)*sin(@.lat2))+(cos(@.lat1)*cos(@.lat2)*cos(@.long1-@.long2)))) > 1.0
SELECT @.dist = 3963.1*acos(1.0)
ELSE
SELECT @.dist = 3963.1*acos((sin(@.lat1)*sin(@.lat2))+(cos(@.lat1)*cos(@.lat2)*cos(@.long1-@.long2)))

-- Return the result of the function
RETURN @.dist

Thanks,

Kyle

What's the problem you're facing? If you want to add a computed column for the distance to the table, you can use something like:

ALTER TABLE dbo.PL_CustomerGeoCode ADD ComputedDistance AS dbo.fn_computeDistance(@.srcLat, cg.geocodeLat, @.srcLong, cg.geocodeLong)