Showing posts with label rows. Show all posts
Showing posts with label rows. Show all posts

Friday, March 23, 2012

parent child relationship

I am using SQL 2000. I have a table with which has both the parent row and child rows.

Pid type status

- - --

1 P 0 -Parent row

2 C 0

3 C 1

4 C 0

I added a new column "Pstatus" to the table. I have to update the table to show the status of parent row against the child row in new col as below.... There are a million records with different parent/child.

Pid type status Pstatus(new col)

- - -- -

1 P 0 0 -Parent row

2 C 0 0

3 C 1 0

4 C 0 0

Thanks...........

How do you know which Parent the Child should be associated with?

It is not clear what you are attempting to accomplish. Please offer more explanition, and perhaps sample data (in the form of INSERT statements).

|||Hey.. What you want to do here? Give more Details?|||

I apologize for the mistake in providing the complete info....The Parent Child relation is defined by Pid..which i have now corrected as below. I hope this helps.....

Pid type status Pstatus(new col)

- - -- -

1 P 0 0 -Parent row

1 C 0 0

1 C 1 0

1 C 0 0

|||

I apologize for the mistake in providing the complete info....The Parent Child relation is defined by Pid..which i have now corrected as below. I hope this helps.....

Pid type status Pstatus(new col)

- - -- -

1 P 0 0 -Parent row

1 C 0 0

1 C 1 0

1 C 0 0

|||

IF PID refers to the Parent, is the record with PID=1 AND Type=P its' own parent? This design only allows for 2 levels.

So, there is no unique identifier for each Child?

Something important is missing here. It seems like there 'should' also an [ID] PRIMARY KEY column. A common design issue is to provide each row with a unique method of distinguishing that row from any other row, and in the case of hierachical designs, also a column to indicate which record is the parent. In this case, while you can create a suposition about parentage by using the [Type] column, you would not be able to tell row 2 from row 4 (using your data above)? Even identical twins have names -and different fingerprints, etc.

Otherwise, as I ask before, how do you determine

partitioning fact table

We have a very big fact table, almost 20million rows for each year, If I partition with each year in the warehouse how can I access all the fact partions as a single fact table when designing it in the data source view in BIDS?

Although I can partition the cube in analysis services by each year, this doesn't seem to solve the problem because the table is enormous and I need to partition it in the warehouse level. Can anyone shed some light?

I will greatly appreciate your feedbacks.

Rok

In SQL 2005 you can create partitioned tables and Indexes and the Query Engine is smart enough to direct requests to a specific partition. You can also store different partitions in different file groups if you want. You should be able to find plenty of documentation in BOL.

But you don't need to have all your data in one table for it to work with BIDS, You can pick one table to work with in the cube designer and then link other tables to specific partitions.

|||

This paper covers both relational and OLAP partitioning for Project REAL:

Project REAL: Data Lifecycle Partitioning

Overview

This paper provides a detailed discussion on how partitioning was implemented, both on the relational data warehouse and in the Analysis Services cubes. In addition to providing the general "how we did it" overview, we include specific code segments and lessons learned in the hopes that the reader will benefit from both our successes and failures. It is our hope that anyone planning or implementing a BI system based on SQL Server 2005 will find the reference implementation useful.

...

Partitioning - logicall transparent?

In Oracle we have implemented database table partitioning for a table
exceeding 130 million rows, to alleviate maintenance issues (update stats,
back up etc). The partitions are by date such that after a month a new table
partition is created and inserts commence on the new partition. In this way
we can update stats on the last partition as required, the older partitions
being effectively static do not need further maintenance. All of this is
transparent to the application the database is supporting, we have also seen
good improvements in query performance.
Is there a way to do this for SQL 2000? Would it be transparent to the
application the database is supporting?
I would expect this table in a particular implementation to exceed 400
million rows per year once in production!
Hi Andy
SQL 2000 cannot partition a table directly - it uses an alternative approach
based on views. It is generally transparent to applications except where the
table being partitioned was using an identity (sequence).
You can read more on partitioned views here:
http://msdn.microsoft.com/library/en...es_06_17zr.asp
SQL Server 2005 includes direct table partitioning, although it's only in
Beta at this stage. It's partitioning support includes range which should
support your date ranges, but not hashlist or composite partitioning.
HTH
Regards,
Greg Linwood
SQL Server MVP
"Andy Black" <Andy Black@.discussions.microsoft.com> wrote in message
news:D34620B3-5E0D-4AFB-B810-5AA2F70A0A47@.microsoft.com...
> In Oracle we have implemented database table partitioning for a table
> exceeding 130 million rows, to alleviate maintenance issues (update stats,
> back up etc). The partitions are by date such that after a month a new
table
> partition is created and inserts commence on the new partition. In this
way
> we can update stats on the last partition as required, the older
partitions
> being effectively static do not need further maintenance. All of this is
> transparent to the application the database is supporting, we have also
seen
> good improvements in query performance.
> Is there a way to do this for SQL 2000? Would it be transparent to the
> application the database is supporting?
> I would expect this table in a particular implementation to exceed 400
> million rows per year once in production!
|||Right now SQL Server 2000 has "distributed partitioned views" to partition
data. While it can have some advantages in the areas you are addressing it
is not as convenient as you would hope in regards to maintenance and such.
SQL 2005 will totally address this issue with some really great partitioning
functionality but it is currently only in Beta. Check out BOL under
"distributed partitioned views" for more information on the current
capabilities and have a look at http://www.microsoft.com/sql/2005/ for 2005
features.
Andrew J. Kelly SQL MVP
"Andy Black" <Andy Black@.discussions.microsoft.com> wrote in message
news:D34620B3-5E0D-4AFB-B810-5AA2F70A0A47@.microsoft.com...
> In Oracle we have implemented database table partitioning for a table
> exceeding 130 million rows, to alleviate maintenance issues (update stats,
> back up etc). The partitions are by date such that after a month a new
table
> partition is created and inserts commence on the new partition. In this
way
> we can update stats on the last partition as required, the older
partitions
> being effectively static do not need further maintenance. All of this is
> transparent to the application the database is supporting, we have also
seen
> good improvements in query performance.
> Is there a way to do this for SQL 2000? Would it be transparent to the
> application the database is supporting?
> I would expect this table in a particular implementation to exceed 400
> million rows per year once in production!

Partitioning - logicall transparent?

In Oracle we have implemented database table partitioning for a table
exceeding 130 million rows, to alleviate maintenance issues (update stats,
back up etc). The partitions are by date such that after a month a new table
partition is created and inserts commence on the new partition. In this way
we can update stats on the last partition as required, the older partitions
being effectively static do not need further maintenance. All of this is
transparent to the application the database is supporting, we have also seen
good improvements in query performance.
Is there a way to do this for SQL 2000? Would it be transparent to the
application the database is supporting?
I would expect this table in a particular implementation to exceed 400
million rows per year once in production!Hi Andy
SQL 2000 cannot partition a table directly - it uses an alternative approach
based on views. It is generally transparent to applications except where the
table being partitioned was using an identity (sequence).
You can read more on partitioned views here:
http://msdn.microsoft.com/library/e...des_06_17zr.asp
SQL Server 2005 includes direct table partitioning, although it's only in
Beta at this stage. It's partitioning support includes range which should
support your date ranges, but not hashlist or composite partitioning.
HTH
Regards,
Greg Linwood
SQL Server MVP
"Andy Black" <Andy Black@.discussions.microsoft.com> wrote in message
news:D34620B3-5E0D-4AFB-B810-5AA2F70A0A47@.microsoft.com...
> In Oracle we have implemented database table partitioning for a table
> exceeding 130 million rows, to alleviate maintenance issues (update stats,
> back up etc). The partitions are by date such that after a month a new
table
> partition is created and inserts commence on the new partition. In this
way
> we can update stats on the last partition as required, the older
partitions
> being effectively static do not need further maintenance. All of this is
> transparent to the application the database is supporting, we have also
seen
> good improvements in query performance.
> Is there a way to do this for SQL 2000? Would it be transparent to the
> application the database is supporting?
> I would expect this table in a particular implementation to exceed 400
> million rows per year once in production!|||Right now SQL Server 2000 has "distributed partitioned views" to partition
data. While it can have some advantages in the areas you are addressing it
is not as convenient as you would hope in regards to maintenance and such.
SQL 2005 will totally address this issue with some really great partitioning
functionality but it is currently only in Beta. Check out BOL under
"distributed partitioned views" for more information on the current
capabilities and have a look at http://www.microsoft.com/sql/2005/ for 2005
features.
Andrew J. Kelly SQL MVP
"Andy Black" <Andy Black@.discussions.microsoft.com> wrote in message
news:D34620B3-5E0D-4AFB-B810-5AA2F70A0A47@.microsoft.com...
> In Oracle we have implemented database table partitioning for a table
> exceeding 130 million rows, to alleviate maintenance issues (update stats,
> back up etc). The partitions are by date such that after a month a new
table
> partition is created and inserts commence on the new partition. In this
way
> we can update stats on the last partition as required, the older
partitions
> being effectively static do not need further maintenance. All of this is
> transparent to the application the database is supporting, we have also
seen
> good improvements in query performance.
> Is there a way to do this for SQL 2000? Would it be transparent to the
> application the database is supporting?
> I would expect this table in a particular implementation to exceed 400
> million rows per year once in production!

Wednesday, March 21, 2012

Partitioning - logicall transparent?

In Oracle we have implemented database table partitioning for a table
exceeding 130 million rows, to alleviate maintenance issues (update stats,
back up etc). The partitions are by date such that after a month a new table
partition is created and inserts commence on the new partition. In this way
we can update stats on the last partition as required, the older partitions
being effectively static do not need further maintenance. All of this is
transparent to the application the database is supporting, we have also seen
good improvements in query performance.
Is there a way to do this for SQL 2000? Would it be transparent to the
application the database is supporting?
I would expect this table in a particular implementation to exceed 400
million rows per year once in production!Hi Andy
SQL 2000 cannot partition a table directly - it uses an alternative approach
based on views. It is generally transparent to applications except where the
table being partitioned was using an identity (sequence).
You can read more on partitioned views here:
http://msdn.microsoft.com/library/en-us/createdb/cm_8_des_06_17zr.asp
SQL Server 2005 includes direct table partitioning, although it's only in
Beta at this stage. It's partitioning support includes range which should
support your date ranges, but not hashlist or composite partitioning.
HTH
Regards,
Greg Linwood
SQL Server MVP
"Andy Black" <Andy Black@.discussions.microsoft.com> wrote in message
news:D34620B3-5E0D-4AFB-B810-5AA2F70A0A47@.microsoft.com...
> In Oracle we have implemented database table partitioning for a table
> exceeding 130 million rows, to alleviate maintenance issues (update stats,
> back up etc). The partitions are by date such that after a month a new
table
> partition is created and inserts commence on the new partition. In this
way
> we can update stats on the last partition as required, the older
partitions
> being effectively static do not need further maintenance. All of this is
> transparent to the application the database is supporting, we have also
seen
> good improvements in query performance.
> Is there a way to do this for SQL 2000? Would it be transparent to the
> application the database is supporting?
> I would expect this table in a particular implementation to exceed 400
> million rows per year once in production!|||Right now SQL Server 2000 has "distributed partitioned views" to partition
data. While it can have some advantages in the areas you are addressing it
is not as convenient as you would hope in regards to maintenance and such.
SQL 2005 will totally address this issue with some really great partitioning
functionality but it is currently only in Beta. Check out BOL under
"distributed partitioned views" for more information on the current
capabilities and have a look at http://www.microsoft.com/sql/2005/ for 2005
features.
--
Andrew J. Kelly SQL MVP
"Andy Black" <Andy Black@.discussions.microsoft.com> wrote in message
news:D34620B3-5E0D-4AFB-B810-5AA2F70A0A47@.microsoft.com...
> In Oracle we have implemented database table partitioning for a table
> exceeding 130 million rows, to alleviate maintenance issues (update stats,
> back up etc). The partitions are by date such that after a month a new
table
> partition is created and inserts commence on the new partition. In this
way
> we can update stats on the last partition as required, the older
partitions
> being effectively static do not need further maintenance. All of this is
> transparent to the application the database is supporting, we have also
seen
> good improvements in query performance.
> Is there a way to do this for SQL 2000? Would it be transparent to the
> application the database is supporting?
> I would expect this table in a particular implementation to exceed 400
> million rows per year once in production!

Parse field into multiple rows

Hello,
I am loading data from our MS Active Directory into our data
warehouse. (check out Mircosofts's Logparser, it can pull data from
ADS, server event logs and more. It can also create text files or load
directly to SQL. Its free and a pretty useful tool)
There is a field that contains the direct reports of a manager. The
direct report users are delimited by a pipe symbol.
I want to breakup the field into multple rows. There can be none, one
or many direct report users in this field.
<disclaimer>
This is a snippet of an example. This is only an example. I know that
I have not defined PK nor indexes. My focus is how to solve a problem
of parsing a field that has multple values into multple rows.
</disclaimer>
Thanks for any help in advance.
Rob

CREATE TABLE "dbo"."F_ADS_MANAGERS"
(
"MANAGER_KEY" VARCHAR(255) NULL,
"DIRECT_REPORTS_CN" VARCHAR(255) NULL
);

INSERT INTO F_ADS_MANAGERS (MANAGER_KEY, DIRECT_REPORTS_CN)
VALUES ('CN=Marilette, 'CN=Robert
D,OU=TechnologyGroup,DC=strayer,DC=edu|CN=Robert
Camarda,OU=TechnologyGroup,DC=strayer,DC=edu|CN=Mi chelle
C,OU=TechnologyGroup,DC=strayer,DC=edu|CN=Magnolia
B,OU=TechnologyGroup,DC=strayer,DC=edu|CN=Lee K,OU=TechnologyGroup')

I want to end up with 5 rows, 1 row for each user that is seprated by
the PIPE symbol.
CN=Marilette CN=Robert D,OU=TechnologyGroup,DC=strayer,DC=edu
CN=Marilette CN=Robert
Camarda,OU=TechnologyGroup,DC=strayer,DC=edu
CN=Marilette CN=Michelle C,OU=TechnologyGroup,DC=strayer,DC=edu
CN=Marilette CN=Magnolia B,OU=TechnologyGroup,DC=strayer,DC=edu
CN=Marilette CN=Lee K,OU=TechnologyGroupHere is one method to split the list using a recursive CTE (this assumes SQL
Server 2005). It is not the fastest, but with a small size list to split it
should be OK.

WITH Managers
(manager_key, direct_reports_cn, start_pos, end_pos)
AS
(
SELECT manager_key,
direct_reports_cn + '|',
1,
CHARINDEX('|', direct_reports_cn + '|')
FROM F_ADS_MANAGERS
UNION ALL
SELECT manager_key,
direct_reports_cn,
end_pos + 1,
CHARINDEX('|', direct_reports_cn, end_pos + 1)
FROM Managers
WHERE CHARINDEX('|', direct_reports_cn, end_pos + 1) 0
)
SELECT manager_key,
SUBSTRING(direct_reports_cn,
start_pos,
end_pos - start_pos) AS direct_report
FROM Managers
WHERE end_pos 0;

Erland Sommarskog has a very good article for arrays and lists that covers
various techniques and analysis:
http://www.sommarskog.se/arrays-in-sql.html
HTH,

Plamen Ratchev
http://www.SQLStudio.com|||Thanks for the link to Erland's article's, it is very handy.
I tried your suggestion but I am confused by the WITH.
I tried
SELECT * FROM F_ADS_MANAGERS
WITH Managers
<snip your code>
and I got an error. Haven't seen this before so I am not sure how to
trouble shoot.
Error I received:
Msg 336, Level 15, State 1, Line 2
Incorrect syntax near 'Managers'. If this is intended to be a common
table expression, you need to explicitly terminate the previous
statement with a semi-colon.

On Jun 27, 10:01 am, "Plamen Ratchev" <Pla...@.SQLStudio.comwrote:

Quote:

Originally Posted by

Here is one method to split the list using a recursive CTE (this assumes SQL
Server 2005). It is not the fastest, but with a small size list to split it
should be OK.
>
WITH Managers
(manager_key, direct_reports_cn, start_pos, end_pos)
AS
(
SELECT manager_key,
direct_reports_cn + '|',
1,
CHARINDEX('|', direct_reports_cn + '|')
FROM F_ADS_MANAGERS
UNION ALL
SELECT manager_key,
direct_reports_cn,
end_pos + 1,
CHARINDEX('|', direct_reports_cn, end_pos + 1)
FROM Managers
WHERE CHARINDEX('|', direct_reports_cn, end_pos + 1) 0
)
SELECT manager_key,
SUBSTRING(direct_reports_cn,
start_pos,
end_pos - start_pos) AS direct_report
FROM Managers
WHERE end_pos 0;
>
Erland Sommarskog has a very good article for arrays and lists that covers
various techniques and analysis:http://www.sommarskog.se/arrays-in-sql.html
>
HTH,
>
Plamen Ratchevhttp://www.SQLStudio.com

|||Here are a few notes that will help you understand the common table
expressions and why you get the error:

- It is required to terminate the statement before the WITH keyword defining
the common table expression with a semicolon. It is because the WITH keyword
has other uses. In your case if you end the select statement in the line
before WITH using ; it will work.
- I am not sure if you understand how CTEs work. CTEs are not materialized
and work pretty much like derived tables (with more functionality, like the
recursion used in this method). They only get defined before the statement
the uses them, so you can reference the CTE only in that statement. There is
a lot more to it, and if you decide to use this method I would suggest to
read more on CTEs in SQL Server Books OnLine.
- If you need to materialize the result of the CTE, you can use INSERT to
insert the data into a temporary table, or just define a view based on the
CTE (or you could also create a function based on the CTE).

Here is a complete example using the approach to define a view based on the
CTE:

CREATE TABLE F_ADS_MANAGERS
(
MANAGER_KEY VARCHAR(255) NULL,
DIRECT_REPORTS_CN VARCHAR(255) NULL
);

INSERT INTO F_ADS_MANAGERS (MANAGER_KEY, DIRECT_REPORTS_CN)
VALUES ('CN=Marilette',
'CN=Robert D,OU=TechnologyGroup,DC=strayer,DC=edu|
CN=Robert Camarda,OU=TechnologyGroup,DC=strayer,DC=edu|
CN=Michelle C,OU=TechnologyGroup,DC=strayer,DC=edu|
CN=Magnolia B,OU=TechnologyGroup,DC=strayer,DC=edu|
CN=Lee K,OU=TechnologyGroup');

GO

CREATE VIEW ManagersWithReports
(manager_key, direct_report)
AS
WITH Managers
(manager_key, direct_reports_cn, start_pos, end_pos)
AS
(
SELECT manager_key,
direct_reports_cn + '|',
1,
CHARINDEX('|', direct_reports_cn + '|')
FROM F_ADS_MANAGERS
UNION ALL
SELECT manager_key,
direct_reports_cn,
end_pos + 1,
CHARINDEX('|', direct_reports_cn, end_pos + 1)
FROM Managers
WHERE CHARINDEX('|', direct_reports_cn, end_pos + 1) 0
)
SELECT manager_key,
SUBSTRING(direct_reports_cn,
start_pos,
end_pos - start_pos) AS direct_report
FROM Managers
WHERE end_pos 0;

GO

SELECT manager_key,
direct_report
FROM ManagersWithReports;

GO

DROP VIEW ManagersWithReports;
DROP TABLE F_ADS_MANAGERS;

GO

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Parse comma separated string into individual rows

All,

Can anyone help me in this task? I have a table named 'Activity' which has two columns: ActivityID and ActivityDetail. Sample rows look like this:

ActivityID ActivityDetail
1 'Football','Basket ball', Tennis'
2 'Basket ball', 'Volley ball'

I would like to have a stored procedure which parses the data into a new table (e.g. named as 'Activity_breadkdown' and with an identity column named 'DetailID') and looks like this:

DetailID ActivityID ActivityDetail
1 1 Football
2 1 Basket ball
3 1 Tennis
4 2 Basket ball
5 2 Volley ball

Thanks in advance
AlYou can modify the code posted in this thread...

http://www.dbforums.com/t974750.html

Parse Array Data Type to Rows

Hi,

We're importing data from a progress db. Some of the columns contain arrays or delimited values which represent accounting periods.

Currently I'm passing the arrays row by row to a stored procedure which parses and inserts each value as a row for the applicable accounting period, it works but is very slow.

Any Ideas?

Thanks

Emilio

In a data flow, use a script task to parse and pivot the array values, then send them to a asynchronous output that writes to the destination table.|||

Hi,

Thank you for the reply.

Do you know of any samples that I can have a look at to get me going in the right direction?

Warm Regards

Emilio

|||

http://agilebi.com/cs/blogs/jwelch/archive/2007/05/17/dynamically-pivoting-columns-to-rows.aspx

Hopefully that will provide a good starting point.

|||

Excellent!!!

I can say that this is the answer to handling those db's that have an array datatype!