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

Friday, March 30, 2012

particulat table in Filegroup

Dear Friends
I have a small database of 1 gb i have created some
Secondary data files for same. in the same database some
tables are extensively used for the Modification hence i
want to separte them form other table datafiles can i do
the same.
please suggest.
Best regards
NiitMaladWhat you can do is create multiple filegroups and assign a datafile to a
filegroup.
You can specify the create table statement with the filegroup it must be
created on
CREATE Table tbl_demo (COL1 INT)
on FILEGROUP
where filegroup is the logical name of the filegroup.
If you have an existing table and you want to place it on another filegroup
you can only create a new table with the ON filegroup keywords, insert from
the first table, delete the first table and rename the new table, what means
: there is no alter table statement to move a table to another filegroup.
You first need to create the filegroups before you create the datafiles and
assign them onto a filegroup
Regards,
Dandy Weyn
MCSE, MCSA, MCDBA, MCT
www.dandyman.net
"niitmalad" <niitmalad@.yahoo.co.in> wrote in message
news:006601c3dd18$6132f930$a101280a@.phx.gbl...
quote:

> Dear Friends
> I have a small database of 1 gb i have created some
> Secondary data files for same. in the same database some
> tables are extensively used for the Modification hence i
> want to separte them form other table datafiles can i do
> the same.
> please suggest.
> Best regards
> NiitMalad
|||> If you have an existing table and you want to place it on another
filegroup
quote:

> you can only create a new table with the ON filegroup keywords

Or you could create a clustered index using the ON filegroup clause, and it
will move the data to the filegroup. Of course, if there's already a
clustered index, you'll have to drop it first. Which complicates things if
it's a referenced primary key.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/

particulat table in Filegroup

Dear Friends
I have a small database of 1 gb i have created some
Secondary data files for same. in the same database some
tables are extensively used for the Modification hence i
want to separte them form other table datafiles can i do
the same.
please suggest.
Best regards
NiitMaladWhat you can do is create multiple filegroups and assign a datafile to a
filegroup.
You can specify the create table statement with the filegroup it must be
created on
CREATE Table tbl_demo (COL1 INT)
on FILEGROUP
where filegroup is the logical name of the filegroup.
If you have an existing table and you want to place it on another filegroup
you can only create a new table with the ON filegroup keywords, insert from
the first table, delete the first table and rename the new table, what means
: there is no alter table statement to move a table to another filegroup.
You first need to create the filegroups before you create the datafiles and
assign them onto a filegroup
--
Regards,
Dandy Weyn
MCSE, MCSA, MCDBA, MCT
www.dandyman.net
"niitmalad" <niitmalad@.yahoo.co.in> wrote in message
news:006601c3dd18$6132f930$a101280a@.phx.gbl...
> Dear Friends
> I have a small database of 1 gb i have created some
> Secondary data files for same. in the same database some
> tables are extensively used for the Modification hence i
> want to separte them form other table datafiles can i do
> the same.
> please suggest.
> Best regards
> NiitMalad|||> If you have an existing table and you want to place it on another
filegroup
> you can only create a new table with the ON filegroup keywords
Or you could create a clustered index using the ON filegroup clause, and it
will move the data to the filegroup. Of course, if there's already a
clustered index, you'll have to drop it first. Which complicates things if
it's a referenced primary key.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/

Partial searches over a lot of fields

Hi All,
I have the following scenario. I have a table called Invoice. This
has around 30 columns of which i have to do a retrieval based on
filter conditions on 10 columns. These filters need to be partial
searches i.e. for e.g the Customer name could be 'Arun', 'Parthiv',
'Aaron', now i should be able to search the customer as 'ar' and it
should return 'Arun' and 'Parthiv'. My concern is there are 10 columns
on which this like '%x%' search has to be done and there will
practically be hudreds of thousands of rows. can anybody suggest me to
improve the performance of such a query. Currently what i am thinkin
of is
select Id, Memo, .. FROM Invoice where CustomerName like '%' + @.Name +
'%' and etc.
P.S. am using ASP.Net as the front end.ArunPrakash (arunprakashb@.yahoo.com) writes:
> I have the following scenario. I have a table called Invoice. This
> has around 30 columns of which i have to do a retrieval based on
> filter conditions on 10 columns. These filters need to be partial
> searches i.e. for e.g the Customer name could be 'Arun', 'Parthiv',
> 'Aaron', now i should be able to search the customer as 'ar' and it
> should return 'Arun' and 'Parthiv'. My concern is there are 10 columns
> on which this like '%x%' search has to be done and there will
> practically be hudreds of thousands of rows. can anybody suggest me to
> improve the performance of such a query. Currently what i am thinkin
> of is
> select Id, Memo, .. FROM Invoice where CustomerName like '%' + @.Name +
> '%' and etc.

You can use SELECT TOP or SET ROWCOUNT to restrict the number of rows
returned. A good value is probably 2000. If you get 2000 rows, you tell
the user to refine his conditions.

Also keep in mind, that there could be a great difference in performance
when searching for names that start with 'Ar', or have 'ar' anywhere in
the name. If the search column is indexed, that index can be used
for the case "starts with", but not "contains".

There are also a couple of considerations of how to compose the query
to make the search effective. You may be interested in the article
http://www.sommarskog.se/dyn-search.html on my web site.

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

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

Partial Restore from Log

We have a database for our Beta site whose backups were not working successfully. A developer inadvertently dropped and recreated a
table with important data in it today, and so we are stuck without a backup.
We would like to restore the database to the state it was in this morning, and hoped to be able to do it from the transaction log.
The problem is, I need to apply the log only up until the point that the DROP TABLE was issued as I don't want to lose the data
again.
All the documentation seems to indicate that what we want to do is possible, but I can't find how to do specifically what we want to
do. Can someone point me in the right direction?Look at the "STOPAT" parameter of the "RESTORE LOG" command in Books Online.
The STOPAT parameter allows you to identify the point in time where you
would like to restore your database to. The time you would want to use is
the point just before your table got deleted.
--
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Erik Moore" <erikmoore@.austin.rr.nospam.com> wrote in message
news:O6LTBdRPEHA.2132@.TK2MSFTNGP11.phx.gbl...
> We have a database for our Beta site whose backups were not working
successfully. A developer inadvertently dropped and recreated a
> table with important data in it today, and so we are stuck without a
backup.
> We would like to restore the database to the state it was in this morning,
and hoped to be able to do it from the transaction log.
> The problem is, I need to apply the log only up until the point that the
DROP TABLE was issued as I don't want to lose the data
> again.
> All the documentation seems to indicate that what we want to do is
possible, but I can't find how to do specifically what we want to
> do. Can someone point me in the right direction?
>
>|||> Look at the "STOPAT" parameter of the "RESTORE LOG" command in Books Online.
Thanks- I was just trying to get STOPAT to work, but I seem to be missing a basic concept or two about the RESTORE LOG command.
I created a copy of my real database by scripting out all the tables and running the script. I figured I would restore the copy of
the database so I could leave all the other data in the production database in tact, and after the restore, I could just copy over
the data from the lost table. I tried:
RESTORE LOG CP2
FROM DISK = 'E:\DATA\MAC\MSSQL\LOG\CPO_LOG.LDF'
WITH NORECOVERY , STOPAT = '2004-02-12 8:30:00'
Where CP2 is the fresh, empty copy of the database, and CPO_LOG is the log from the real database. (I have taken CPO offline
temporarily). But when I run the code above, I get the following message:
"Server: Msg 4306, Level 16, State 1, Line 1
The preceding restore operation did not specify WITH NORECOVERY or WITH STANDBY. Restart the restore sequence, specifying WITH
NORECOVERY or WITH STANDBY for all but the final step.
Server: Msg 3013, Level 16, State 1, Line 1
RESTORE LOG is terminating abnormally."
All the examples I can find seem to assume that I have a database backup that I am restoring from first, and _then_ I will apply the
log.|||The basic concept of getting this to work, is making sure you have a
complete sequence of backups. Meaning you need at a mimimum a full database
backup and a transaction log backup where the table was deleted (provided no
other backups occured between the full and the transaction log backup) If
there were a number of transaction logs since the last full backup you need
all these backups. Also if you performed differential backups then based on
which files you are using for the restore you might need one of those. Do
you have all these backups, a complete sequence of backups from the full to
that last transaction log backup? If you don't have a complete set of
backups you will not be able to perform what I suggested.
Also the transaction log backup is not the actual transaction log (file
ending in .LDF), but separate file that is created when you issue a BACKUP
LOG command. Based on your restore command looks like you are trying to use
the actual transcation log for your "FROM DISK=" option.
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Erik Moore" <erikmoore@.austin.rr.nospam.com> wrote in message
news:%23MqGiBSPEHA.308@.TK2MSFTNGP11.phx.gbl...
> > Look at the "STOPAT" parameter of the "RESTORE LOG" command in Books
Online.
> Thanks- I was just trying to get STOPAT to work, but I seem to be missing
a basic concept or two about the RESTORE LOG command.
> I created a copy of my real database by scripting out all the tables and
running the script. I figured I would restore the copy of
> the database so I could leave all the other data in the production
database in tact, and after the restore, I could just copy over
> the data from the lost table. I tried:
> RESTORE LOG CP2
> FROM DISK = 'E:\DATA\MAC\MSSQL\LOG\CPO_LOG.LDF'
> WITH NORECOVERY , STOPAT = '2004-02-12 8:30:00'
> Where CP2 is the fresh, empty copy of the database, and CPO_LOG is the log
from the real database. (I have taken CPO offline
> temporarily). But when I run the code above, I get the following message:
> "Server: Msg 4306, Level 16, State 1, Line 1
> The preceding restore operation did not specify WITH NORECOVERY or WITH
STANDBY. Restart the restore sequence, specifying WITH
> NORECOVERY or WITH STANDBY for all but the final step.
> Server: Msg 3013, Level 16, State 1, Line 1
> RESTORE LOG is terminating abnormally."
> All the examples I can find seem to assume that I have a database backup
that I am restoring from first, and _then_ I will apply the
> log.
>
>|||> The basic concept of getting this to work, is making sure you have a
> complete sequence of backups.
Well the problem is, there are _no_ backups of the database or of the log. But as I understand it, since the log was not backup up
at all, it should contain all the transactions since the birth of the database. (The log file is some 5GB in size).
I was hoping to accomplish this by starting with an empty database (the way it was when the log was started), and just applying the
complete log.
I'm getting a sinking feeling that this may not be possible?|||If you don't have a full backup of you database then you are correct and you
can't restore from the transaction log. One glimmer of hope might be to try
and use a third party tools to get information out of the transaction log.
I've never used these. There is a tool called "Log Explorer" from Lumigent
which might help you out.
--
----
----
--
Need SQL Server Examples check out my website at
http://www.geocities.com/sqlserverexamples
"Erik Moore" <erikmoore@.austin.rr.nospam.com> wrote in message
news:OK668PSPEHA.1512@.TK2MSFTNGP10.phx.gbl...
> > The basic concept of getting this to work, is making sure you have a
> > complete sequence of backups.
> Well the problem is, there are _no_ backups of the database or of the log.
But as I understand it, since the log was not backup up
> at all, it should contain all the transactions since the birth of the
database. (The log file is some 5GB in size).
> I was hoping to accomplish this by starting with an empty database (the
way it was when the log was started), and just applying the
> complete log.
> I'm getting a sinking feeling that this may not be possible?
>
>
>|||Thanks, I really appreciate your help. We're looking at alternative means of restoring the data from a sencondary source.
"Gregory A. Larsen" <greg.larsen@.netzero.com> wrote in message news:uSmtaXSPEHA.2636@.TK2MSFTNGP10.phx.gbl...
> If you don't have a full backup of you database then you are correct and you
> can't restore from the transaction log. One glimmer of hope might be to try
> and use a third party tools to get information out of the transaction log.
> I've never used these. There is a tool called "Log Explorer" from Lumigent
> which might help you out.
> --
> ----
> ----
> --
> Need SQL Server Examples check out my website at
> http://www.geocities.com/sqlserverexamples
> "Erik Moore" <erikmoore@.austin.rr.nospam.com> wrote in message
> news:OK668PSPEHA.1512@.TK2MSFTNGP10.phx.gbl...
> > > The basic concept of getting this to work, is making sure you have a
> > > complete sequence of backups.
> >
> > Well the problem is, there are _no_ backups of the database or of the log.
> But as I understand it, since the log was not backup up
> > at all, it should contain all the transactions since the birth of the
> database. (The log file is some 5GB in size).
> >
> > I was hoping to accomplish this by starting with an empty database (the
> way it was when the log was started), and just applying the
> > complete log.
> >
> > I'm getting a sinking feeling that this may not be possible?
> >
> >
> >
> >
> >
>|||<<Well the problem is, there are _no_ backups of the database or of the log. But as I understand it, since the
log was not backup up at all, it should contain all the transactions since the birth of the database.>>
Above is a common misconception. Until you do your first database backup, the database is in "auto log
truncate mode" which means that SQL Server will truncate the log when 70% full or at checkpoint. So, you
cannot be certain to find your log records even when using some log reader tool.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Erik Moore" <erikmoore@.austin.rr.nospam.com> wrote in message news:OK668PSPEHA.1512@.TK2MSFTNGP10.phx.gbl...
> > The basic concept of getting this to work, is making sure you have a
> > complete sequence of backups.
> Well the problem is, there are _no_ backups of the database or of the log. But as I understand it, since the
log was not backup up
> at all, it should contain all the transactions since the birth of the database. (The log file is some 5GB in
size).
> I was hoping to accomplish this by starting with an empty database (the way it was when the log was
started), and just applying the
> complete log.
> I'm getting a sinking feeling that this may not be possible?
>
>
>

Partial Restore (only of a table)

Do I need the bank in the air for 24:00, is there as I do a partial restore
of a backup, in other words, without stopping the bank in use to just
recuperate a table of your backup?Restore the database to somewhere else and DTS the table across.
Frank Dulk wrote:
> Do I need the bank in the air for 24:00, is there as I do a partial restore
> of a backup, in other words, without stopping the bank in use to just
> recuperate a table of your backup?
>
--
Allan Mitchell (Microsoft SQL Server MVP)
MCSE,MCDBA
www.SQLDTS.com
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org

Partial Replication

Hi
Is it possible to replicate just some records in a table and can the filter
be implemented (I am trying to avoid a situation that employees will have
the full version database while they are away from the office [they only
need te records that are assigned to them])
Thank you,
Shmuel Shulman
SBS Technologies LTD
See "replication, filtering options" in BOL.
"S Shulman" <smshulman@.hotmail.com> wrote in message
news:uB8E%2378hFHA.2472@.TK2MSFTNGP15.phx.gbl...
> Hi
> Is it possible to replicate just some records in a table and can the
> filter be implemented (I am trying to avoid a situation that employees
> will have the full version database while they are away from the office
> [they only need te records that are assigned to them])
> Thank you,
> Shmuel Shulman
> SBS Technologies LTD
>
|||You can filter replication horizontally or vertically using a filter
you create.
Example:
You have a table that has a column "User"
In the merge agent parameters use option -Hosname [Dave] ( or whatever
value works)
Then in the filter clause use:
User = hostname()
That particular subscriber will only get records where User = "Dave"
This is for merge and I'm not sure about the other types of
replication.
|||Thanks all for your help
Shmuel
<seanbell68@.gmail.com> wrote in message
news:1121305341.878967.300120@.o13g2000cwo.googlegr oups.com...
> You can filter replication horizontally or vertically using a filter
> you create.
> Example:
> You have a table that has a column "User"
> In the merge agent parameters use option -Hosname [Dave] ( or whatever
> value works)
> Then in the filter clause use:
> User = hostname()
> That particular subscriber will only get records where User = "Dave"
> This is for merge and I'm not sure about the other types of
> replication.
>

Parsing XML

I am importing an xml document into a table in SQL Server (SS) 2005.
It imports into a single column (XML datatype). After that I use the
script below to parse it out into different rows in another table.
select xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Nu)[1]',
xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Do_IP)[1]',
xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Sy_Type)[1]',
from xmlimport
In the xml document there are more than one record. How do I loop
through the xml document? Or in other words change the [1] to [2]..
.
[3]...[4]...
I know it is easy, but for some reason I can't figure it out.
Anyone know?
Thanks!
chfranYou probably want to use the nodes() method. Can you post some sample XML
data?
Here's an idea if your data follows the format given:
CREATE TABLE #xmlimport (xmldata xml);
INSERT INTO #xmlimport (xmldata)
VALUES (N'<Lab_Exceptions>
<Lab_Exception_Data>
<A_Data>
<Ex_Station_Nu>100</Ex_Station_Nu>
<Ex_Station_Do_IP>192.168.10.1</Ex_Station_Do_IP>
<Ex_Station_Sy_Type>Type A</Ex_Station_Sy_Type>
</A_Data>
<A_Data>
<Ex_Station_Nu>200</Ex_Station_Nu>
<Ex_Station_Do_IP>192.168.10.2</Ex_Station_Do_IP>
<Ex_Station_Sy_Type>Type B</Ex_Station_Sy_Type>
</A_Data>
</Lab_Exception_Data>
</Lab_Exceptions>');
SELECT c.value('Ex_Station_Nu[1]', 'int') AS Ex_Station_Nu,
c.value('Ex_Station_Do_IP[1]', 'varchar(100)') AS Ex_Station_Do_IP,
c.value('Ex_Station_Sy_Type[1]', 'varchar(100)') AS Ex_Station_Sy_Type
FROM #xmlimport x
CROSS APPLY x.xmldata.nodes('/Lab_Exceptions/Lab_Exception_Data/A_Data') AS
T(c);
DROP TABLE #xmlimport;
"chfran" <chfran@.gmail.com> wrote in message
news:9a50a933-c824-4d71-8864-8be76493a22e@.s19g2000prg.googlegroups.com...
>I am importing an xml document into a table in SQL Server (SS) 2005.
> It imports into a single column (XML datatype). After that I use the
> script below to parse it out into different rows in another table.
> select xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Nu)[1]',
> xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Do_IP)[1]',
> xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Sy_Type)[1]',
> from xmlimport
> In the xml document there are more than one record. How do I loop
> through the xml document? Or in other words change the [1] to [2]
..
> [3]...[4]...
> I know it is easy, but for some reason I can't figure it out.
> Anyone know?
> Thanks!
> chfran

Parsing XML

I am importing an xml document into a table in SQL Server (SS) 2005.
It imports into a single column (XML datatype). After that I use the
script below to parse it out into different rows in another table.
select xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Nu)[1]',
xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Do_IP)[1]',
xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Sy_Type)[1]',
from xmlimport
In the xml document there are more than one record. How do I loop
through the xml document? Or in other words change the [1] to [2]...
[3]...[4]...
I know it is easy, but for some reason I can't figure it out.
Anyone know?
Thanks!
chfran
You probably want to use the nodes() method. Can you post some sample XML
data?
Here's an idea if your data follows the format given:
CREATE TABLE #xmlimport (xmldata xml);
INSERT INTO #xmlimport (xmldata)
VALUES (N'<Lab_Exceptions>
<Lab_Exception_Data>
<A_Data>
<Ex_Station_Nu>100</Ex_Station_Nu>
<Ex_Station_Do_IP>192.168.10.1</Ex_Station_Do_IP>
<Ex_Station_Sy_Type>Type A</Ex_Station_Sy_Type>
</A_Data>
<A_Data>
<Ex_Station_Nu>200</Ex_Station_Nu>
<Ex_Station_Do_IP>192.168.10.2</Ex_Station_Do_IP>
<Ex_Station_Sy_Type>Type B</Ex_Station_Sy_Type>
</A_Data>
</Lab_Exception_Data>
</Lab_Exceptions>');
SELECT c.value('Ex_Station_Nu[1]', 'int') AS Ex_Station_Nu,
c.value('Ex_Station_Do_IP[1]', 'varchar(100)') AS Ex_Station_Do_IP,
c.value('Ex_Station_Sy_Type[1]', 'varchar(100)') AS Ex_Station_Sy_Type
FROM #xmlimport x
CROSS APPLY x.xmldata.nodes('/Lab_Exceptions/Lab_Exception_Data/A_Data') AS
T(c);
DROP TABLE #xmlimport;
"chfran" <chfran@.gmail.com> wrote in message
news:9a50a933-c824-4d71-8864-8be76493a22e@.s19g2000prg.googlegroups.com...
>I am importing an xml document into a table in SQL Server (SS) 2005.
> It imports into a single column (XML datatype). After that I use the
> script below to parse it out into different rows in another table.
> select xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Nu)[1]',
> xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Do_IP)[1]',
> xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Sy_Type)[1]',
> from xmlimport
> In the xml document there are more than one record. How do I loop
> through the xml document? Or in other words change the [1] to [2]...
> [3]...[4]...
> I know it is easy, but for some reason I can't figure it out.
> Anyone know?
> Thanks!
> chfran

Parsing XML

I am importing an xml document into a table in SQL Server (SS) 2005.
It imports into a single column (XML datatype). After that I use the
script below to parse it out into different rows in another table.
select xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Nu)[1]',
xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Do_IP)[1]',
xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
Ex_Station_Sy_Type)[1]',
from xmlimport
In the xml document there are more than one record. How do I loop
through the xml document? Or in other words change the [1] to [2]...
[3]...[4]...
I know it is easy, but for some reason I can't figure it out.
Anyone know?
Thanks!
chfranYou probably want to use the nodes() method. Can you post some sample XML
data?
Here's an idea if your data follows the format given:
CREATE TABLE #xmlimport (xmldata xml);
INSERT INTO #xmlimport (xmldata)
VALUES (N'<Lab_Exceptions>
<Lab_Exception_Data>
<A_Data>
<Ex_Station_Nu>100</Ex_Station_Nu>
<Ex_Station_Do_IP>192.168.10.1</Ex_Station_Do_IP>
<Ex_Station_Sy_Type>Type A</Ex_Station_Sy_Type>
</A_Data>
<A_Data>
<Ex_Station_Nu>200</Ex_Station_Nu>
<Ex_Station_Do_IP>192.168.10.2</Ex_Station_Do_IP>
<Ex_Station_Sy_Type>Type B</Ex_Station_Sy_Type>
</A_Data>
</Lab_Exception_Data>
</Lab_Exceptions>');
SELECT c.value('Ex_Station_Nu[1]', 'int') AS Ex_Station_Nu,
c.value('Ex_Station_Do_IP[1]', 'varchar(100)') AS Ex_Station_Do_IP,
c.value('Ex_Station_Sy_Type[1]', 'varchar(100)') AS Ex_Station_Sy_Type
FROM #xmlimport x
CROSS APPLY x.xmldata.nodes('/Lab_Exceptions/Lab_Exception_Data/A_Data') AS
T(c);
DROP TABLE #xmlimport;
"chfran" <chfran@.gmail.com> wrote in message
news:9a50a933-c824-4d71-8864-8be76493a22e@.s19g2000prg.googlegroups.com...
>I am importing an xml document into a table in SQL Server (SS) 2005.
> It imports into a single column (XML datatype). After that I use the
> script below to parse it out into different rows in another table.
> select xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Nu)[1]',
> xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Do_IP)[1]',
> xmldata.value('(/Lab_Exceptions/Lab_Exception_Data/A_Data/
> Ex_Station_Sy_Type)[1]',
> from xmlimport
> In the xml document there are more than one record. How do I loop
> through the xml document? Or in other words change the [1] to [2]...
> [3]...[4]...
> I know it is easy, but for some reason I can't figure it out.
> Anyone know?
> Thanks!
> chfran

Wednesday, March 28, 2012

Parsing T-SQL is not validating table schemas

I am curious why my stored procedures are parsing properly when you do not reference a table with its schema. The stored procs then fail when you run them.

It seems that the parser does not validate that a tables schema is missing.

This is an example stored procedure against the Person.Address table in the Adventureworks database. It will execute fine if I change the FROM clause to Person.Address.


CREATE PROCEDURE [dbo].[Address_Load]
@.AddressID [int]
AS
BEGIN
SET NOCOUNT ON;

DECLARE @.intError int

BEGIN TRY
SELECT A.[AddressID]
, A.[AddressLine1]
, A.[AddressLine2]
, A.[City]
, A.[StateProvinceID]
, A.[PostalCode]
FROM [Address] A
WHERE A.[AddressID] = @.AddressID

IF @.@.ROWCOUNT = 0
BEGIN
RAISERROR('Record not found', 16, 1) -- Record not found.
END

-- Return success
RETURN 0
END TRY
BEGIN CATCH
SET @.intError = ERROR_NUMBER();

-- Log error here

RETURN @.intError;
END CATCH
END

The stored proc parses fine and gets saved to the database but when executing it I get the following

Msg 208, Level 16, State 1, Procedure Address_Load, Line 10

Invalid object name 'Address'.

Is there any way to change this so the parsing will generate an error and not allow this into the database?

Thanks,

Cory

The behavior is due to deferred name resolution/compilation of TSQL modules in SQL Server. You can look it up in BOL for more details. See link below for starters:

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

|||

And when you decide you don't like the behavior, please go here and vote!

https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124490

It is good about 1% of the time to be like this. However, the problem is the 2% of the time when you are coding and mistype a table name and it still compiles, only to find out later when you are (hopefully) testing :)

|||Is there a way to turn off Deferred Name Resolution?|||

Nope. That is what this feedback that I mentioned:

https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124490

It really ought to be a settting you can ask for, not soemthing that is on all of the time.

Parsing string and Inserting each element?

Hi All,
I'll try and make this simple.
I have a column in a table that has one or more values separated by a comma.
Ex: 1234,456,322,33445,abce,ekksks
I want to go through each record and take this column data and parse it out,
then insert each element into another table.
ex:
INSERT Into GTable (RecordID, ItemValue)
Values (NewID(), <Parsed Values from each record's
Column> )
Any ideas would be greatly appreciated.
John.Arrays and Lists in SQL Server
http://www.sommarskog.se/arrays-in-sql.html
Faking arrays in T-SQL stored procedures
http://www.bizdatasolutions.com/tsql/sqlarrays.asp
How do I simulate an array inside a stored procedure?
http://www.aspfaq.com/show.asp?id=2248
AMB
"John Rugo" wrote:

> Hi All,
> I'll try and make this simple.
> I have a column in a table that has one or more values separated by a comm
a.
> Ex: 1234,456,322,33445,abce,ekksks
> I want to go through each record and take this column data and parse it ou
t,
> then insert each element into another table.
> ex:
> INSERT Into GTable (RecordID, ItemValue)
> Values (NewID(), <Parsed Values from each record's
> Column> )
> Any ideas would be greatly appreciated.
> John.
>
>|||Do you mean inserting each value as a separate row? If I were to create the
insert statements manually for your example, would it look like:
INSERT INTO(GTable (RecordID, ItemValue)
Values (NewID(), '1234')
INSERT INTO(GTable (RecordID, ItemValue)
Values (NewID(), '456')
INSERT INTO(GTable (RecordID, ItemValue)
Values (NewID(), '322')
INSERT INTO(GTable (RecordID, ItemValue)
Values (NewID(), '33445')
INSERT INTO(GTable (RecordID, ItemValue)
Values (NewID(), 'abce')
INSERT INTO(GTable (RecordID, ItemValue)
Values (NewID(), 'ekksks')
?
If so, then a cursor would probably be the best way to go (hopefully this is
a one time thing, because as we all know, cursors as the devil)...
If you want some quickly hacked code as an example of how the cursor would
work, post back and I'll see if I can put something together..
-Cliff
"John Rugo" <jrugo@.patmedia.net> wrote in message
news:Ot0XwOsPFHA.4028@.tk2msftngp13.phx.gbl...
> Hi All,
> I'll try and make this simple.
> I have a column in a table that has one or more values separated by a
comma.
> Ex: 1234,456,322,33445,abce,ekksks
> I want to go through each record and take this column data and parse it
out,
> then insert each element into another table.
> ex:
> INSERT Into GTable (RecordID, ItemValue)
> Values (NewID(), <Parsed Values from each record's
> Column> )
> Any ideas would be greatly appreciated.
> John.
>|||John,
Here is an efficient way to do this - it's buried in one of the articles
Alejandro referred you to.
/*
A table-valued function with one parameter, a delimited list,
that returns the separate distinct items of the list.
Steve Kass, Drew University
Thanks to MVPs Linda Wierzbicki and Umachandar Jayachandran
for help and helpful discussions on this.
*/
--A table of integers is needed
create table Seq (
Nbr int not null
)
insert into Seq
select top 4001 0
from Northwind..[Order Details]
cross join (select 1 as n union all select 2) X
declare @.i int
set @.i = -1
update Seq
set @.i = Nbr = @.i + 1
alter table Seq add constraint pk_Seq primary key (Nbr)
--table Seq created
go
--This makes things more readable. The list is easier
--to process if it begins and ends with a single comma
--As it turns out also, list items cannot
--have leading or trailing spaces (here any leading spaces
--in the first item or trailing spaces in the last are
--eliminated)
create function RegularizedList (@.List varchar(8000))
returns varchar(8000) as begin
return replace(rtrim(','+ltrim(@.List))+',', ',,', ',')
end
go
--This function returns a table containing one column, commaPos,
--of integers, the positions of each comma in @.List, except the last
--This function returns a table containing the items in the list.
--The items are extracted by selecting those substrings of
--the list that begin immediately after a comma and end
--immediately before the next comma, then trimming spaces on
--both sides.
create function ListTable (@.List varchar(8000))
returns table as return
select
ltrim(rtrim(
substring(regL,
commaPos+1,
charindex(',', regL, commaPos+1) - (commaPos+1))))
as Item
from (
select Nbr as commaPos
from Seq, (
select dbo.RegularizedList(@.List) as regL
) R
where substring(regL,Nbr,1) = ','
and Nbr < len(regL)
) L, (
select dbo.RegularizedList(@.List) as regL
) R
go
--examples
declare @.x varchar(4000), @.time datetime
set @.time = getdate()
set @.x = replicate('foo,bar,foo,bar,ab,',30) + 'end'
select distinct Item from ListTable(@.x)
select datediff(ms,@.time,getdate())
set @.x = '10245 10345 98292 '
declare @.s varchar(400)
set @.s = replace(@.x,' ',',')
select * from ListTable(@.s)
--Note, if a list contains a non-comma delimiter, and contains no
--commas within items, this replacement allows the function to
--handle it. If a comma appears in an item, but some other non-
--delimiter is absent from the list, a three-step replacement can
--be made:
-- replace all commas with new character not in list
-- replace all delimiters with comma
-- Use (select replace(Item,<new>,<comma> ) from ListTable(@.List)) LT
-- where the list table is used.
go
--Since this is a repro script, delete everything!
--Keep them around if they are helpful, though.
DROP FUNCTION RegularizedList
DROP TABLE Seq
DROP FUNCTION ListTable
-- Steve Kass
-- Drew University
John Rugo wrote:

>Hi All,
>I'll try and make this simple.
>I have a column in a table that has one or more values separated by a comma
.
>Ex: 1234,456,322,33445,abce,ekksks
>I want to go through each record and take this column data and parse it out
,
>then insert each element into another table.
>ex:
>INSERT Into GTable (RecordID, ItemValue)
> Values (NewID(), <Parsed Values from each record's
>Column> )
>Any ideas would be greatly appreciated.
>John.
>
>

Parse the field

I have a table that has a "Problem" field with the following data
Customer Service...Jam...Jam 5...Planned
Technical Support...WinOnCD...WinOnCD6PowerEdition...Request...Reporting
New Drive
Sale Made
I need to separate this "Problem" field into separate fields the issue1,
issue2, issue3, issue4 and issue5 (Customer Service, Jam, Jam 5,Planned
) .
What would be the easiest way to do so within the SELECT statement ?here's a quick and dirty way of parsing out the data:::
declare @.myString varchar(2000) --Set to max length of field
declare @.Issue1 varchar(100) --Set to max length of any single entry
set @.myString = 'Customer Service...Jam...Jam 5...Planned '
set @.myString = 'Technical
Support...WinOnCD...WinOnCD6PowerEdition...Request...Reporting '
--set @.myString = 'New Drive'
declare @.Index int -- Holds the next position of delimeter
declare @.delimiter char(1) -- holds delimeter character
set @.delimiter = '.' -- set the delimer value
set @.Index = patindex( '%'+@.delimiter+'%',@.myString) -- get first instance
of delimeter
-- run a loop while we still have delimeters in the string
while @.Index>0
begin
-- get the next value
set @.Issue1 = substring(@.myString,1,@.Index-1)
-- do whatever you wish with the value print, save to table, array, etc)
print @.Issue1
-- parse the latest value from the current string
set @.myString = substring(@.myString,@.Index+3,len(@.myString))
-- get the next instance of the delimeter
set @.Index = patindex( '%'+@.delimiter+'%',@.myString)
end
-- Get the last value from what's left
set @.Issue1 = ltrim(rtrim(@.myString))
-- do whatever you wish with the value print, save to table, array, etc)
print @.Issue1
Copy and paste it into QA and you can see how it works for you
Tony
"agenda9533" wrote:
> I have a table that has a "Problem" field with the following data
> Customer Service...Jam...Jam 5...Planned
> Technical Support...WinOnCD...WinOnCD6PowerEdition...Request...Reporting
> New Drive
> Sale Made
> I need to separate this "Problem" field into separate fields the issue1,
> issue2, issue3, issue4 and issue5 (Customer Service, Jam, Jam 5,Planned
> ) .
> What would be the easiest way to do so within the SELECT statement ?|||This is awesome!
Only thing, Ijust don't know how to run/call this script within RS.
As far as I know RS only recognize T-Sql SELECT statements (in order to
create a dataset).
Am I wrong?
"Logicalman" wrote:
> here's a quick and dirty way of parsing out the data:::
>
> declare @.myString varchar(2000) --Set to max length of field
> declare @.Issue1 varchar(100) --Set to max length of any single entry
> set @.myString = 'Customer Service...Jam...Jam 5...Planned '
> set @.myString = 'Technical
> Support...WinOnCD...WinOnCD6PowerEdition...Request...Reporting '
> --set @.myString = 'New Drive'
> declare @.Index int -- Holds the next position of delimeter
> declare @.delimiter char(1) -- holds delimeter character
> set @.delimiter = '.' -- set the delimer value
> set @.Index = patindex( '%'+@.delimiter+'%',@.myString) -- get first instance
> of delimeter
> -- run a loop while we still have delimeters in the string
> while @.Index>0
> begin
> -- get the next value
> set @.Issue1 = substring(@.myString,1,@.Index-1)
> -- do whatever you wish with the value print, save to table, array, etc)
> print @.Issue1
> -- parse the latest value from the current string
> set @.myString = substring(@.myString,@.Index+3,len(@.myString))
> -- get the next instance of the delimeter
> set @.Index = patindex( '%'+@.delimiter+'%',@.myString)
> end
> -- Get the last value from what's left
> set @.Issue1 = ltrim(rtrim(@.myString))
> -- do whatever you wish with the value print, save to table, array, etc)
> print @.Issue1
>
> Copy and paste it into QA and you can see how it works for you
> Tony
> "agenda9533" wrote:
> > I have a table that has a "Problem" field with the following data
> >
> > Customer Service...Jam...Jam 5...Planned
> >
> > Technical Support...WinOnCD...WinOnCD6PowerEdition...Request...Reporting
> > New Drive
> >
> > Sale Made
> >
> > I need to separate this "Problem" field into separate fields the issue1,
> > issue2, issue3, issue4 and issue5 (Customer Service, Jam, Jam 5,Planned
> > ) .
> >
> > What would be the easiest way to do so within the SELECT statement ?|||My first suggestion would be to place this in a Stored Procedure, and call
the SProc as the dataset for the RS report.
"agenda9533" wrote:
> This is awesome!
> Only thing, Ijust don't know how to run/call this script within RS.
> As far as I know RS only recognize T-Sql SELECT statements (in order to
> create a dataset).
> Am I wrong?
> "Logicalman" wrote:
> > here's a quick and dirty way of parsing out the data:::
> >
> >
> > declare @.myString varchar(2000) --Set to max length of field
> > declare @.Issue1 varchar(100) --Set to max length of any single entry
> >
> > set @.myString = 'Customer Service...Jam...Jam 5...Planned '
> > set @.myString = 'Technical
> > Support...WinOnCD...WinOnCD6PowerEdition...Request...Reporting '
> > --set @.myString = 'New Drive'
> >
> > declare @.Index int -- Holds the next position of delimeter
> > declare @.delimiter char(1) -- holds delimeter character
> > set @.delimiter = '.' -- set the delimer value
> >
> > set @.Index = patindex( '%'+@.delimiter+'%',@.myString) -- get first instance
> > of delimeter
> > -- run a loop while we still have delimeters in the string
> > while @.Index>0
> > begin
> > -- get the next value
> > set @.Issue1 = substring(@.myString,1,@.Index-1)
> > -- do whatever you wish with the value print, save to table, array, etc)
> > print @.Issue1
> > -- parse the latest value from the current string
> > set @.myString = substring(@.myString,@.Index+3,len(@.myString))
> > -- get the next instance of the delimeter
> > set @.Index = patindex( '%'+@.delimiter+'%',@.myString)
> >
> > end
> > -- Get the last value from what's left
> > set @.Issue1 = ltrim(rtrim(@.myString))
> > -- do whatever you wish with the value print, save to table, array, etc)
> > print @.Issue1
> >
> >
> > Copy and paste it into QA and you can see how it works for you
> >
> > Tony
> >
> > "agenda9533" wrote:
> >
> > > I have a table that has a "Problem" field with the following data
> > >
> > > Customer Service...Jam...Jam 5...Planned
> > >
> > > Technical Support...WinOnCD...WinOnCD6PowerEdition...Request...Reporting
> > > New Drive
> > >
> > > Sale Made
> > >
> > > I need to separate this "Problem" field into separate fields the issue1,
> > > issue2, issue3, issue4 and issue5 (Customer Service, Jam, Jam 5,Planned
> > > ) .
> > >
> > > What would be the easiest way to do so within the SELECT statement ?

Monday, March 26, 2012

Parenthesis in field value

Hello all

I have a table called PRODUCT and the unique field in the table is called PARTNUMBER like so:

PARTNUMBER DESCRIPTION
12345(6) Widget 1
12347(5) Widget 2

my select SQL looks like this
SELECT * FROM PRODUCT WHERE PARTNUMBER = '12345(6)'

That statement fails. what can I do to get around this error?

Regards
The CaptainThe only obvious thing I can think of is that you should use the double quotes and not the single quotes.

This works in SQL View in Access:

SELECT PRODUCT.*, PRODUCT.PARTNUMBER
FROM PRODUCT
WHERE (((PRODUCT.PARTNUMBER)="12345(6)"));|||How does the statement fail? Does it produce an error message?

-PatP

parentheses in a check constraint

Can we use parentheses in a check constraint in MS-SQL-server DDL?

e.g. I'm having a problem with the following statement:

ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [CK_MyTable_TimesDataOK]
CHECK (([TimeOn] IS NULL AND [TimeOff] IS NULL)
OR
([ShiftCode] IS NOT NULL AND [TimeOn] IS NOT NULL AND [TimeOff] IS NOT
NULL));

The statement appears to run fine, but when I look at my table
definition afterwards, it appears that SQL-server ignored the
parentheses in my constraint; it shows the constraint expression as:
(([TimeOn] IS NULL AND [TimeOff] IS NULL OR [ShiftCode] IS NOT NULL AND
[TimeOn] IS NOT NULL AND [TimeOff] IS NOT NULL))

My intention is that if there's (non null) data in either of the columns
TimeOn or TimeOff is not null, all three of the columns TimeOn, TimeOff
and ShiftCode must have non null data.

OK, I realise I could enforce this by altering my table setup in other
ways. Right now I'm just trying to figure out if this I'm just up
against a difference between dialects of SQL in check constraints here.
Am I missing something obvious with parentheses?

BTW the DDL for the table I'm testing on:
CREATE TABLE [dbo].[MyTable](
[FNname] [nvarchar](50) NOT NULL,
[ShiftDate] [datetime] NOT NULL,
[ShiftCode] [nchar](2) NULL,
[TimeOn] [nchar](4) NULL,
[TimeOff] [nchar](4) NULL);Helen Wheels <helenwheelss@.yahoo.com.auwrote in
news:136mli9pi74bs63@.corp.supernews.com:

Quote:

Originally Posted by

Can we use parentheses in a check constraint in MS-SQL-server DDL?
>
e.g. I'm having a problem with the following statement:
>
ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [CK_MyTable_TimesDataOK]
CHECK (([TimeOn] IS NULL AND [TimeOff] IS NULL)
OR
([ShiftCode] IS NOT NULL AND [TimeOn] IS NOT NULL AND [TimeOff]
IS NOT
NULL));
>
The statement appears to run fine, but when I look at my table
definition afterwards, it appears that SQL-server ignored the
parentheses in my constraint; it shows the constraint expression as:
(([TimeOn] IS NULL AND [TimeOff] IS NULL OR [ShiftCode] IS NOT NULL
AND [TimeOn] IS NOT NULL AND [TimeOff] IS NOT NULL))
>
My intention is that if there's (non null) data in either of the
columns TimeOn or TimeOff is not null, all three of the columns
TimeOn, TimeOff and ShiftCode must have non null data.
>
OK, I realise I could enforce this by altering my table setup in other
ways. Right now I'm just trying to figure out if this I'm just up
against a difference between dialects of SQL in check constraints
here. Am I missing something obvious with parentheses?
>
BTW the DDL for the table I'm testing on:
CREATE TABLE [dbo].[MyTable](
[FNname] [nvarchar](50) NOT NULL,
[ShiftDate] [datetime] NOT NULL,
[ShiftCode] [nchar](2) NULL,
[TimeOn] [nchar](4) NULL,
[TimeOff] [nchar](4) NULL);
>


"When more than one logical operator is used in a statement, the AND
operators are evaluated first ..." (BOL) - your inner parentheses are
therefore unnecessary.|||Chris.Cheney wrote:

Quote:

Originally Posted by

Helen Wheels <helenwheelss@.yahoo.com.auwrote in
news:136mli9pi74bs63@.corp.supernews.com:
>
>

Quote:

Originally Posted by

>>Can we use parentheses in a check constraint in MS-SQL-server DDL?
>>
>>e.g. I'm having a problem with the following statement:
>>
>>ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [CK_MyTable_TimesDataOK]
>>CHECK (([TimeOn] IS NULL AND [TimeOff] IS NULL)
> OR
> ([ShiftCode] IS NOT NULL AND [TimeOn] IS NOT NULL AND [TimeOff]
> IS NOT
>>NULL));
>>
>>The statement appears to run fine, but when I look at my table
>>definition afterwards, it appears that SQL-server ignored the
>>parentheses in my constraint; it shows the constraint expression as:
>>(([TimeOn] IS NULL AND [TimeOff] IS NULL OR [ShiftCode] IS NOT NULL
>>AND [TimeOn] IS NOT NULL AND [TimeOff] IS NOT NULL))
>>
>>My intention is that if there's (non null) data in either of the
>>columns TimeOn or TimeOff is not null, all three of the columns
>>TimeOn, TimeOff and ShiftCode must have non null data.
>>
>>OK, I realise I could enforce this by altering my table setup in other
>>ways. Right now I'm just trying to figure out if this I'm just up
>>against a difference between dialects of SQL in check constraints
>>here. Am I missing something obvious with parentheses?
>>
>>BTW the DDL for the table I'm testing on:
>>CREATE TABLE [dbo].[MyTable](
> [FNname] [nvarchar](50) NOT NULL,
> [ShiftDate] [datetime] NOT NULL,
> [ShiftCode] [nchar](2) NULL,
> [TimeOn] [nchar](4) NULL,
> [TimeOff] [nchar](4) NULL);
>>


>
>
"When more than one logical operator is used in a statement, the AND
operators are evaluated first ..." (BOL) - your inner parentheses are
therefore unnecessary.


So they are. The constraint is working as expected, it just doesn't look
quite the way I'm used to reading it. Thanks.|||Helen Wheels (helenwheelss@.yahoo.com.au) writes:

Quote:

Originally Posted by

Can we use parentheses in a check constraint in MS-SQL-server DDL?
>
e.g. I'm having a problem with the following statement:
>
ALTER TABLE [dbo].[MyTable] ADD CONSTRAINT [CK_MyTable_TimesDataOK]
CHECK (([TimeOn] IS NULL AND [TimeOff] IS NULL)
OR
([ShiftCode] IS NOT NULL AND [TimeOn] IS NOT NULL AND [TimeOff] IS
NOT NULL));
>
The statement appears to run fine, but when I look at my table
definition afterwards, it appears that SQL-server ignored the
parentheses in my constraint; it shows the constraint expression as:
(([TimeOn] IS NULL AND [TimeOff] IS NULL OR [ShiftCode] IS NOT NULL AND
[TimeOn] IS NOT NULL AND [TimeOff] IS NOT NULL))


SQL Server does not store the constraint text as provided, but performs
some normalisations on it. One such normalisation is apparently to
remove superfluous parantheses. Your original constraint text and what
SQL Server saved, are equivalent. AND binds tighter than OR, so these
two are the same:

x AND y OR a AND b
(x ANY y) OR (a AND b)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Parent-Child relationship

I have a field which is the primary key in table A, and in table B i have th
e
same field which is the foreign key.When it comes to deleting a record I
should kill the child first.If i try to delete the parent then i get an
error, which is expected. But if i turn the delete cascade option on, it let
s
me delete the parent first without giving an error.Why?
Thanks in advance.On Tue, 15 Feb 2005 08:21:11 -0800, PH wrote:

>I have a field which is the primary key in table A, and in table B i have t
he
>same field which is the foreign key.When it comes to deleting a record I
>should kill the child first.If i try to delete the parent then i get an
>error, which is expected. But if i turn the delete cascade option on, it le
ts
>me delete the parent first without giving an error.Why?
>Thanks in advance.
Hi PH,
Because the on delete cascade options tells the SQL Server engine that it
should automatically delete all "orphaned" childs when you delete a
parent. After SQL Server has done that, there are no more rows violating
the foreign key constraint, so there's no reason to give you an error.
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||What did you think that cascade would do? The error is not there because
it deleted the child first, then deleted the parent.
----
Louis Davidson - drsql@.hotmail.com
SQL Server MVP
Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Blog - http://spaces.msn.com/members/drsql/
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)
"PH" <PH@.discussions.microsoft.com> wrote in message
news:AE79F794-3984-4DE6-949B-C395B817E144@.microsoft.com...
>I have a field which is the primary key in table A, and in table B i have
>the
> same field which is the foreign key.When it comes to deleting a record I
> should kill the child first.If i try to delete the parent then i get an
> error, which is expected. But if i turn the delete cascade option on, it
> lets
> me delete the parent first without giving an error.Why?
> Thanks in advance.|||Only use cascade delete when you are always sure that it never makes sense
to have a child when the parent is deleted. There are cases where it makes
sense for a child to have a null in the FK column, usually this is when
there are multiple Fk's in the child table, BUT, the is usually always ONE
Master table, as in Invoice and InvoiceItem when you must decide to either
cascade delete the InvoiceItem when and Invoice is deleted or to DENY
deleting and Invoice if it has InvoiceItems. This is a business rule that
you must decide on.
JIM
"PH" <PH@.discussions.microsoft.com> wrote in message
news:AE79F794-3984-4DE6-949B-C395B817E144@.microsoft.com...
>I have a field which is the primary key in table A, and in table B i have
>the
> same field which is the foreign key.When it comes to deleting a record I
> should kill the child first.If i try to delete the parent then i get an
> error, which is expected. But if i turn the delete cascade option on, it
> lets
> me delete the parent first without giving an error.Why?
> Thanks in advance.|||Thanks for your answers
"james" wrote:

> Only use cascade delete when you are always sure that it never makes sense
> to have a child when the parent is deleted. There are cases where it make
s
> sense for a child to have a null in the FK column, usually this is when
> there are multiple Fk's in the child table, BUT, the is usually always ONE
> Master table, as in Invoice and InvoiceItem when you must decide to either
> cascade delete the InvoiceItem when and Invoice is deleted or to DENY
> deleting and Invoice if it has InvoiceItems. This is a business rule that
> you must decide on.
> JIM
> "PH" <PH@.discussions.microsoft.com> wrote in message
> news:AE79F794-3984-4DE6-949B-C395B817E144@.microsoft.com...
>
>

Parent-Child Hierarchy but reversed(!)

Hi!

I have a report that uses a parent-child hierarchy in a table. It is hidden with the toggle set to itself, and that works perfectly.

However, instead of having it look like this(simple example):

+ Profit

After the + has been clicked:

-Profit
+Sales
+Cost

I would like it to look like this:

+Sales
+Cost
-Profit

Is this possible with when using a parent-child hierarchy?

http://ssasfreak.spaces.live.com/

Have you tried using the group footer row instead of the group header row to control visibility?|||

Yes. That only works when you have the diffrent levels in different fields. Like this:

Level1 Level2 Level2

I use the parentgroup property(for the grouping) with a recordset that looks like this:

LevelID LevelName ParentLevelID

Any ideas?

Parent-child dimension related to fact table

is it possible to use a "regular relation" to connect fact table to a
parent-child dimension?
thanksOoops! I'm using Analysis Services 2005 :-)

Parent-child dimension

I'm trying to connect a parent-child dimension to my fact table.
I would like to browse cube measure (sold items quantity) through the
dimension "Groups" representing items family (tree structure).
Here are the tables:
Fact table (items sold with quantity):
--
IdItem;Quantity
1;5
2;2
3;1
1;6
3;8
--
Dimension table (parent-child tree representing groups item):
--
IdGroup;GroupName;IdParent;IdItem
1;AAA;-1;-1
2;BBB;1;-1
3;CCC;1;-1
4;O1;2;1
5;O2;2;2
6;O3;3;3
--
If I connect dimension to fact table with a regular relation (on IdItem
attribute of each table) and browse cube, I obtain for each node the
same quantity (22)
AAA (22)
-BBB (22)
--O1 (22)
--O2 (22)
-CCC (22)
--O3 (22)
I would like to obtain this result:
AAA (22)
-BBB (13)
--O1 (11)
--O2 (2)
-CCC (9)
--O3 (9)
If I use a "reference relation" with a middle table it's ok...
but I don't understand the difference!!!!!!
Can someone help me?
thanksOoops! I'm using Analysis Services 2005 :-)

> I'm trying to connect a parent-child dimension to my fact table.
> I would like to browse cube measure (sold items quantity) through the
> dimension "Groups" representing items family (tree structure).
> Here are the tables:
> Fact table (items sold with quantity):
> --
> IdItem;Quantity
> 1;5
> 2;2
> 3;1
> 1;6
> 3;8
> --
> Dimension table (parent-child tree representing groups item):
> --
> IdGroup;GroupName;IdParent;IdItem
> 1;AAA;-1;-1
> 2;BBB;1;-1
> 3;CCC;1;-1
> 4;O1;2;1
> 5;O2;2;2
> 6;O3;3;3
> --
> If I connect dimension to fact table with a regular relation (on IdItem
> attribute of each table) and browse cube, I obtain for each node the
> same quantity (22)
> AAA (22)
> -BBB (22)
> --O1 (22)
> --O2 (22)
> -CCC (22)
> --O3 (22)
> I would like to obtain this result:
> AAA (22)
> -BBB (13)
> --O1 (11)
> --O2 (2)
> -CCC (9)
> --O3 (9)
> If I use a "reference relation" with a middle table it's ok...
> but I don't understand the difference!!!!!!
> Can someone help me?
> thanks

parent/child text File Import


I have a file with a parent child records in the same file.

My game plan is to get it into a table recognize the parents and put them in the parent table and recognize the children and put them in the children table.

The problem I am having is the flat file import chokes on it because the column withs are different from line to line (parent / child).

Any thoughts or suggestions would be apprecaited.

Mardo

You'll need to import the data into the pipeline as a single wide column and then parse out the required values using a combination of the condistional split component and derived column component.

-Jamie

parent/child table error in sqlxml

When I try to select with sqlxml I recevie the following error related to on
e
relationship that has a composite key (all none composite key relationships
work).
Schema: the parent/child table of the relationship on
'ProductMetricsBreakDown' does not match.
The xsd is included that is causing the error is included
It is the AnnualBusinessModel_ProductMetricsBreakD
own that is giving me the
error.
Any help would be greatly appreciated.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
<xs:annotation>
<xs:appinfo>
<sql:relationship name=" MicrosoftPartnerProfile_AnnualBusinessMo
del"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="AnnualBusinessModel" child-key="AccountID" />
<sql:relationship name="MicrosoftPartnerProfile_Branch"
parent="MicrosoftPartnerProfile" parent-key="AccountID" child="Branch"
child-key="AccountID" />
<sql:relationship name="MicrosoftPartnerProfile_BusinessFocus"
parent="MicrosoftPartnerProfile" parent-key="AccountID" child="BusinessFocus
"
child-key="AccountID" />
<sql:relationship name="MicrosoftPartnerProfile_FormUI"
parent="MicrosoftPartnerProfile" parent-key="AccountID" child="FormUI"
child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_LinksToOtherDocu
ments"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="LinksToOtherDocuments" child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_NotesAndConditio
ns"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="NotesAndConditions" child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_PartnerAssessmen
t"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="PartnerAssessment" child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_PartnerCompetenc
y"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="PartnerCompetency" child-key="AccountID" />
<sql:relationship name="MicrosoftPartnerProfile_PartnerGTM"
parent="MicrosoftPartnerProfile" parent-key="AccountID" child="PartnerGTM"
child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_PartnerIndustryV
ertical"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="PartnerIndustryVertical" child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_PartnerSalesVert
ical"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="PartnerSalesVertical" child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_PartnerSpecializ
ation"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="PartnerSpecialization" child-key="AccountID" />
<sql:relationship name=" MicrosoftPartnerProfile_RevenueBreakdown
"
parent="MicrosoftPartnerProfile" parent-key="AccountID"
child="RevenueBreakdown" child-key="AccountID" />
<sql:relationship name="MicrosoftPartnerProfile_Contact"
parent="MicrosoftPartnerProfile" parent-key="AccountID" child="Contact"
child-key="AccountID" />
<sql:relationship name=" AnnualBusinessModel_ProductMetricsBreakD
own"
parent="AnnualBusinessModel" parent-key="AccountID CalendarYear"
child="ProductMetricsBreakDown" child-key="AccountID CalendarYear" />
<!--<sql:relationship name=" AnnualBusinessModel_ProductMetricsBreakD
own"
parent="AnnualBusinessModel" parent-key="CalendarYear"
child="ProductMetricsBreakDown" child-key="CalendarYear" /> -->
<!--
<sql:relationship name=" AnnualBusinessModel_ProductMetricsBreakD
own"
parent="AnnualBusinessModel" parent-key="AccountID CalendarYear"
child="ProductMetricsBreakDown" child-key="AccountID CalendarYear" />
<sql:relationship name="RevenueBreakdown_RevenueBreakdownDetail"
parent="RevenueBreakdown" parent-key="AccountID BusinessSectionID
CalendarYear" child="RevenueBreakdownDetail" child-key="AccountID
BusinessSectionID CalendarYear" />
-->
</xs:appinfo>
</xs:annotation>
<xs:element name="MicrosoftPartnerProfile"
sql:relation="MicrosoftPartnerProfile">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="NativeID" sql:field="NativeID" sql:datatype="int" />
<xs:element name="CertificationTierLevelID"
sql:field="CertificationTierLevelID" sql:datatype="varchar" />
<xs:element name="CompanyName" sql:field="CompanyName"
sql:datatype="varchar" />
<xs:element name="DoingBusinessAsName" sql:field="DoingBusinessAsName"
sql:datatype="varchar" />
<xs:element name="GeographicAreaID" sql:field="GeographicAreaID"
sql:datatype="int" />
<xs:element name="Region" sql:field="Region" sql:datatype="varchar" />
<xs:element name="District" sql:field="District" sql:datatype="varchar" />
<xs:element name="MatrixID" sql:field="MatrixID" sql:datatype="int" />
<xs:element name="NumberOfEmployees" sql:field="NumberOfEmployees"
sql:datatype="int" />
<xs:element name="NumberOfSalesProfessionals"
sql:field="NumberOfSalesProfessionals" sql:datatype="int" />
<xs:element name="NumberOfEmployeesPerUPP"
sql:field="NumberOfEmployeesPerUPP" sql:datatype="varchar" />
<xs:element name="NumberOfTechProfessionals"
sql:field="NumberOfTechProfessionals" sql:datatype="int" />
<xs:element name="OrgHQLocationIndicator"
sql:field="OrgHQLocationIndicator" sql:datatype="varchar" />
<xs:element name="NumberOfSalesProfessionalsPerUPP"
sql:field="NumberOfSalesProfessionalsPerUPP" sql:datatype="varchar" />
<xs:element name="GlobalPartner" sql:field="GlobalPartner"
sql:datatype="varchar" />
<xs:element name="ActiveFlag" sql:field="ActiveFlag"
sql:datatype="varchar" />
<xs:element name="NumberOfTechProfessionalsPerUPP"
sql:field="NumberOfTechProfessionalsPerUPP" sql:datatype="varchar" />
<xs:element name="MSOrganizationID" sql:field="MSOrganizationID"
sql:datatype="int" />
<xs:element name="Seg_1_49_Percent" sql:field="Seg_1_49_Percent"
sql:datatype="decimal" />
<xs:element name="Seg_50_999_Percent" sql:field="Seg_50_999_Percent"
sql:datatype="decimal" />
<xs:element name="Seg_1000_14999_Percent"
sql:field="Seg_1000_14999_Percent" sql:datatype="decimal" />
<xs:element name="Seg_15000_Percent" sql:field="Seg_15000_Percent"
sql:datatype="decimal" />
<xs:element name="AddressLine1" sql:field="AddressLine1"
sql:datatype="varchar" />
<xs:element name="AddressLine2" sql:field="AddressLine2"
sql:datatype="varchar" />
<xs:element name="City" sql:field="City" sql:datatype="varchar" />
<xs:element name="PostalCode" sql:field="PostalCode"
sql:datatype="varchar" />
<xs:element name="StateProvinceId" sql:field="StateProvinceId"
sql:datatype="varchar" />
<xs:element name="Phone" sql:field="Phone" sql:datatype="varchar" />
<xs:element name="SiebelID" sql:field="SiebelID" sql:datatype="int" />
<xs:element name="StatusID" sql:field="StatusID" sql:datatype="varchar" />
<xs:element name="ProfileDueDate" sql:field="ProfileDueDate"
sql:datatype="datetime" />
<xs:element name="ManagedBy" sql:field="ManagedBy"
sql:datatype="varchar" />
<xs:element name="ParentAccountID" sql:field="ParentAccountID"
sql:datatype="int" />
<xs:element name="UPPID" sql:field="UPPID" sql:datatype="int" />
<xs:element name="LastModifiedBy" sql:field="LastModifiedBy"
sql:datatype="varchar" />
<xs:element name="LastModifiedDate" sql:field="LastModifiedDate"
sql:datatype="datetime" />
<xs:element name="ParentUPPId" sql:field="ParentUPPId"
sql:datatype="int" />
<xs:element name="CustomCampaign" sql:field="CustomCampaign"
sql:datatype="varchar" />
<xs:element name="PartnerSalesVertical"
sql:relation="PartnerSalesVertical"
sql:relationship=" MicrosoftPartnerProfile_PartnerSalesVert
ical"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="SalesVerticalID" sql:field="SalesVerticalID"
sql:datatype="int" />
<xs:element name="Checked" sql:field="Checked" sql:datatype="varchar"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PartnerIndustryVertical"
sql:relation="PartnerIndustryVertical"
sql:relationship=" MicrosoftPartnerProfile_PartnerIndustryV
ertical"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="IndustryVerticalID" sql:field="IndustryVerticalID"
sql:datatype="int" />
<xs:element name="Checked" sql:field="Checked" sql:datatype="varchar"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PartnerGTM" sql:relation="PartnerGTM"
sql:relationship="MicrosoftPartnerProfile_PartnerGTM" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="GTMFocusID" sql:field="GTMFocusID"
sql:datatype="int" />
<xs:element name="Checked" sql:field="Checked" sql:datatype="varchar"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PartnerCompetency" sql:relation="PartnerCompetency"
sql:relationship=" MicrosoftPartnerProfile_PartnerCompetenc
y"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="CompetencyID" sql:field="CompetencyID"
sql:datatype="int" />
<xs:element name="Checked" sql:field="Checked" sql:datatype="varchar"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="FormUI" sql:relation="FormUI"
sql:relationship="MicrosoftPartnerProfile_FormUI" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="CompetencyCheckMode"
sql:field="CompetencyCheckMode" sql:datatype="varchar" />
<xs:element name="SpecializationCheckModel"
sql:field="SpecializationCheckModel" sql:datatype="varchar" />
<xs:element name="ProductsCheckMode" sql:field="ProductsCheckMode"
sql:datatype="varchar" />
<xs:element name="IndustryVerticalsCheckMode"
sql:field="IndustryVerticalsCheckMode" sql:datatype="varchar" />
<xs:element name="MBSVerticalsCheckMode"
sql:field="MBSVerticalsCheckMode" sql:datatype="varchar" />
<xs:element name="GTMSCheckMode" sql:field="GTMSCheckMode"
sql:datatype="varchar" />
<xs:element name="AssessmentsCheckMode"
sql:field="AssessmentsCheckMode" sql:datatype="varchar" />
<xs:element name="AnnualBusinessCurrentMode"
sql:field="AnnualBusinessCurrentMode" sql:datatype="varchar" />
<xs:element name="BusinessPlanCurrentMode"
sql:field="BusinessPlanCurrentMode" sql:datatype="varchar" />
<xs:element name="NavProfileStatus" sql:field="NavProfileStatus"
sql:datatype="varchar" />
<xs:element name="NavCoreInformation" sql:field="NavCoreInformation"
sql:datatype="varchar" />
<xs:element name="NavBusinessFocus" sql:field="NavBusinessFocus"
sql:datatype="varchar" />
<xs:element name="NavContact" sql:field="NavContact"
sql:datatype="varchar" />
<xs:element name="NavBranch" sql:field="NavBranch"
sql:datatype="varchar" />
<xs:element name="NavCompetency" sql:field="NavCompetency"
sql:datatype="varchar" />
<xs:element name="NavSpecialization" sql:field="NavSpecialization"
sql:datatype="varchar" />
<xs:element name="NavIndustryVert" sql:field="NavIndustryVert"
sql:datatype="varchar" />
<xs:element name="NavMBSVert" sql:field="NavMBSVert"
sql:datatype="varchar" />
<xs:element name="NavRevSummary" sql:field="NavRevSummary"
sql:datatype="varchar" />
<xs:element name="NavConditions" sql:field="NavConditions"
sql:datatype="varchar" />
<xs:element name="NavRhythm" sql:field="NavRhythm"
sql:datatype="varchar" />
<xs:element name="NavCampaigns" sql:field="NavCampaigns"
sql:datatype="varchar" />
<xs:element name="NavAssessments" sql:field="NavAssessments"
sql:datatype="varchar" />
<xs:element name="NavLinks" sql:field="NavLinks"
sql:datatype="varchar" />
<xs:element name="NavProducts" sql:field="NavProducts"
sql:datatype="varchar" />
<xs:element name="NavPlanStatus" sql:field="NavPlanStatus"
sql:datatype="varchar" />
<xs:element name="NavGoalSummary" sql:field="NavGoalSummary"
sql:datatype="varchar" />
<xs:element name="NavInvestments" sql:field="NavInvestments"
sql:datatype="varchar" />
<xs:element name="NavSolutionPlan" sql:field="NavSolutionPlan"
sql:datatype="varchar" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="LinksToOtherDocuments"
sql:relation="LinksToOtherDocuments"
sql:relationship=" MicrosoftPartnerProfile_LinksToOtherDocu
ments">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="DocumentUrl" sql:field="DocumentUrl"
sql:datatype="varchar" />
<xs:element name="DocumentTitle" sql:field="DocumentTitle"
sql:datatype="varchar" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="NotesAndConditions" sql:relation="NotesAndConditions"
sql:relationship=" MicrosoftPartnerProfile_NotesAndConditio
ns">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="MeetingFrequencyID" sql:field="MeetingFrequencyID"
sql:datatype="int" />
<xs:element name="ConditionsOfSatisfaction"
sql:field="ConditionsOfSatisfaction" sql:datatype="varchar" />
<xs:element name="Notes" sql:field="Notes" sql:datatype="varchar" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PartnerAssessment" sql:relation="PartnerAssessment"
sql:relationship=" MicrosoftPartnerProfile_PartnerAssessmen
t">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="AssessmentTypeID" sql:field="AssessmentTypeID"
sql:datatype="int" />
<xs:element name="Checked" sql:field="Checked" sql:datatype="varchar"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="AnnualBusinessModel"
sql:relation="AnnualBusinessModel"
sql:relationship=" MicrosoftPartnerProfile_AnnualBusinessMo
del">
<xs:complexType>
<xs:sequence>
<xs:element name="PartnerFiscalYearEndDate"
sql:field="PartnerFiscalYearEndDate" sql:datatype="datetime" />
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="CalendarYear" sql:field="CalendarYear"
sql:datatype="int" />
<xs:element name="AnnualRevenueInMillions"
sql:field="AnnualRevenueInMillions" sql:datatype="decimal" />
<xs:element name="RevenueGrowthPercentYOY"
sql:field="RevenueGrowthPercentYOY" sql:datatype="decimal" />
<xs:element name="AnnualRevenuePerUPP"
sql:field="AnnualRevenuePerUPP" sql:datatype="decimal" />
<xs:element name="AnnualMSRevenueInMillions"
sql:field="AnnualMSRevenueInMillions" sql:datatype="decimal" />
<xs:element name="AnnualSoftMSRevenuePerUPP"
sql:field="AnnualSoftMSRevenuePerUPP" sql:datatype="decimal" />
<xs:element name="MSRevenueGrowthPercentYOY"
sql:field="MSRevenueGrowthPercentYOY" sql:datatype="decimal" />
<xs:element name="PercentCRM" sql:field="PercentCRM"
sql:datatype="decimal" />
<xs:element name="PercentERP" sql:field="PercentERP"
sql:datatype="decimal" />
<xs:element name="HighlightedProductSubcategoryID"
sql:field="HighlightedProductSubcategoryID" sql:datatype="int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="BusinessFocus" sql:relation="BusinessFocus"
sql:relationship="MicrosoftPartnerProfile_BusinessFocus">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="BluePrintQuadrantID"
sql:field="BluePrintQuadrantID" sql:datatype="int" />
<xs:element name="PartnerTypeID" sql:field="PartnerTypeID"
sql:datatype="varchar" />
<xs:element name="DistrictPref1" sql:field="DistrictPref1"
sql:datatype="int" />
<xs:element name="DistrictPref2" sql:field="DistrictPref2"
sql:datatype="int" />
<xs:element name="DistrictPref3" sql:field="DistrictPref3"
sql:datatype="int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="PartnerSpecialization"
sql:relation="PartnerSpecialization"
sql:relationship=" MicrosoftPartnerProfile_PartnerSpecializ
ation">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="SpecializationID" sql:field="SpecializationID"
sql:datatype="int" />
<xs:element name="Checked" sql:field="Checked" sql:datatype="varchar"
/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="ProductMetricsBreakDown"
sql:relation="ProductMetricsBreakDown"
sql:relationship=" AnnualBusinessModel_ProductMetricsBreakD
own" >
<xs:complexType>
<xs:sequence>
<xs:element name="MetricId" sql:field="MetricId" sql:datatype="int" />
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="CalendarYear" sql:field="CalendarYear"
sql:datatype="int" />
<xs:element name="ProductSubCategoryID"
sql:field="ProductSubCategoryID" sql:datatype="int" />
<xs:element name="MetricName" sql:field="MetricName"
sql:datatype="varchar" />
<xs:element name="ProductSubcategoryName"
sql:field="ProductSubcategoryName" sql:datatype="varchar" />
<xs:element name="Half1MSGoal" sql:field="Half1MSGoal"
sql:datatype="decimal" />
<xs:element name="Half1NonMSGoal" sql:field="Half1NonMSGoal"
sql:datatype="decimal" />
<xs:element name="Half1MSActual" sql:field="Half1MSActual"
sql:datatype="decimal" />
<xs:element name="Half1NonMSActual" sql:field="Half1NonMSActual"
sql:datatype="decimal" />
<xs:element name="Half2MSGoal" sql:field="Half2MSGoal"
sql:datatype="decimal" />
<xs:element name="Half2NonMSGoal" sql:field="Half2NonMSGoal"
sql:datatype="decimal" />
<xs:element name="Half2MSActual" sql:field="Half2MSActual"
sql:datatype="decimal" />
<xs:element name="Half2NonMSActual" sql:field="Half2NonMSActual"
sql:datatype="decimal" />
<xs:element name="Total" sql:field="Total" sql:datatype="decimal" />
<xs:element name="TotalPercentage" sql:field="TotalPercentage"
sql:datatype="decimal" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Branch" sql:relation="Branch"
sql:relationship="MicrosoftPartnerProfile_Branch">
<xs:complexType>
<xs:sequence>
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="BranchAccountID" sql:field="BranchAccountID"
sql:datatype="nvarchar" />
<xs:element name="ExecuteOnLocalMarketingCampaigns"
sql:field="ExecuteOnLocalMarketingCampaigns" sql:datatype="varchar" />
<xs:element name="BusinessSectionID" sql:field="BusinessSectionID"
sql:datatype="int" />
<xs:element name="BusinessSectionID1" sql:field="BusinessSectionID1"
sql:datatype="int" />
<xs:element name="BusinessSectionID2" sql:field="BusinessSectionID2"
sql:datatype="int" />
<xs:element name="EngagementTypeID" sql:field="EngagementTypeID"
sql:datatype="int" />
<xs:element name="EngagementTypeID1" sql:field="EngagementTypeID1"
sql:datatype="int" />
<xs:element name="EngagementTypeID2" sql:field="EngagementTypeID2"
sql:datatype="int" />
<xs:element name="ExecuteOnMSOpportunityForecasting"
sql:field="ExecuteOnMSOpportunityForecasting" sql:datatype="varchar" />
<xs:element name="AddressLine1" sql:field="AddressLine1"
sql:datatype="varchar" />
<xs:element name="SubDistrictID" sql:field="SubDistrictID"
sql:datatype="int" />
<xs:element name="City" sql:field="City" sql:datatype="varchar" />
<xs:element name="StateProvinceID" sql:field="StateProvinceID"
sql:datatype="varchar" />
<xs:element name="PostalCode" sql:field="PostalCode"
sql:datatype="varchar" />
<xs:element name="NumberOfLocalSalesProfessionals"
sql:field="NumberOfLocalSalesProfessionals" sql:datatype="int" />
<xs:element name="NumberOfLocalTechProfessionals"
sql:field="NumberOfLocalTechProfessionals" sql:datatype="int" />
<xs:element name="BranchName" sql:field="BranchName"
sql:datatype="varchar" />
</xs:sequence>
</xs:complexType>
</xs:element>
<!--
<xs:element name="RevenueBreakdown" sql:relation="RevenueBreakdown">
<xs:complexType>
<xs:sequence>
<xs:element name="BusinessSectionID" sql:field="BusinessSectionID"
sql:datatype="int" />
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="CalendarYear" sql:field="CalendarYear"
sql:datatype="int" />
<xs:element name="PercentMS" sql:field="PercentMS"
sql:datatype="decimal" />
<xs:element name="PercentNonMS" sql:field="PercentNonMS"
sql:datatype="decimal" />
<xs:element name="PercentOfTotal" sql:field="PercentOfTotal"
sql:datatype="decimal" />
<xs:element name="ChildrenVisible" sql:field="ChildrenVisible"
sql:datatype="varchar" />
<xs:element name="RevenueBreakdownDetail"
sql:relation="RevenueBreakdownDetail"
sql:relationship="RevenueBreakdown_RevenueBreakdownDetail"
maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="BusinessSubsectionID"
sql:field="BusinessSubsectionID" sql:datatype="int" />
<xs:element name="AccountID" sql:field="AccountID"
sql:datatype="nvarchar" />
<xs:element name="BusinessSectionID" sql:field="BusinessSectionID"
sql:datatype="int" />
<xs:element name="CalendarYear" sql:field="CalendarYear"
sql:datatype="int" />
<xs:element name="PercentMS" sql:field="PercentMS"
sql:datatype="decimal" />
<xs:element name="PercentNonMS" sql:field="PercentNonMS"
sql:datatype="decimal" />
<xs:element name="PercentOfTotal" sql:field="PercentOfTotal"
sql:datatype="decimal" />
<xs:element name="ChildrenVisible" sql:field="ChildrenVisible"
sql:datatype="varchar" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
-->
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>I resolved the problem. Since this productmetrics table was a child of the
annualbusinessmodel table, it had to be nested in the schema.
:>
"jb" wrote:
> When I try to select with sqlxml I recevie the following error related to
one
> relationship that has a composite key (all none composite key relationship
s
> work).
> Schema: the parent/child table of the relationship on
> 'ProductMetricsBreakDown' does not match.
> The xsd is included that is causing the error is included
> It is the AnnualBusinessModel_ProductMetricsBreakD
own that is giving me th
e
> error.
> Any help would be greatly appreciated.
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema elementFormDefault="qualified"
> xmlns:xs="http://www.w3.org/2001/XMLSchema"
> xmlns:sql="urn:schemas-microsoft-com:mapping-schema">
> <xs:annotation>
> <xs:appinfo>
> <sql:relationship name=" MicrosoftPartnerProfile_AnnualBusinessMo
del"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="AnnualBusinessModel" child-key="AccountID" />
> <sql:relationship name="MicrosoftPartnerProfile_Branch"
> parent="MicrosoftPartnerProfile" parent-key="AccountID" child="Branch"
> child-key="AccountID" />
> <sql:relationship name="MicrosoftPartnerProfile_BusinessFocus"
> parent="MicrosoftPartnerProfile" parent-key="AccountID" child="BusinessFoc
us"
> child-key="AccountID" />
> <sql:relationship name="MicrosoftPartnerProfile_FormUI"
> parent="MicrosoftPartnerProfile" parent-key="AccountID" child="FormUI"
> child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_LinksToOtherDocu
ments"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="LinksToOtherDocuments" child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_NotesAndConditio
ns"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="NotesAndConditions" child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_PartnerAssessmen
t"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="PartnerAssessment" child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_PartnerCompetenc
y"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="PartnerCompetency" child-key="AccountID" />
> <sql:relationship name="MicrosoftPartnerProfile_PartnerGTM"
> parent="MicrosoftPartnerProfile" parent-key="AccountID" child="PartnerGTM"
> child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_PartnerIndustryV
ertical
"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="PartnerIndustryVertical" child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_PartnerSalesVert
ical"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="PartnerSalesVertical" child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_PartnerSpecializ
ation"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="PartnerSpecialization" child-key="AccountID" />
> <sql:relationship name=" MicrosoftPartnerProfile_RevenueBreakdown
"
> parent="MicrosoftPartnerProfile" parent-key="AccountID"
> child="RevenueBreakdown" child-key="AccountID" />
> <sql:relationship name="MicrosoftPartnerProfile_Contact"
> parent="MicrosoftPartnerProfile" parent-key="AccountID" child="Contact"
> child-key="AccountID" />
> <sql:relationship name=" AnnualBusinessModel_ProductMetricsBreakD
own"
> parent="AnnualBusinessModel" parent-key="AccountID CalendarYear"
> child="ProductMetricsBreakDown" child-key="AccountID CalendarYear" />
> <!--<sql:relationship name=" AnnualBusinessModel_ProductMetricsBreakD
own
"
> parent="AnnualBusinessModel" parent-key="CalendarYear"
> child="ProductMetricsBreakDown" child-key="CalendarYear" /> -->
> <!--
> <sql:relationship name=" AnnualBusinessModel_ProductMetricsBreakD
own"
> parent="AnnualBusinessModel" parent-key="AccountID CalendarYear"
> child="ProductMetricsBreakDown" child-key="AccountID CalendarYear" />
> <sql:relationship name="RevenueBreakdown_RevenueBreakdownDetail"
> parent="RevenueBreakdown" parent-key="AccountID BusinessSectionID
> CalendarYear" child="RevenueBreakdownDetail" child-key="AccountID
> BusinessSectionID CalendarYear" />
> -->
> </xs:appinfo>
> </xs:annotation>
> <xs:element name="MicrosoftPartnerProfile"
> sql:relation="MicrosoftPartnerProfile">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="NativeID" sql:field="NativeID" sql:datatype="int" />
> <xs:element name="CertificationTierLevelID"
> sql:field="CertificationTierLevelID" sql:datatype="varchar" />
> <xs:element name="CompanyName" sql:field="CompanyName"
> sql:datatype="varchar" />
> <xs:element name="DoingBusinessAsName" sql:field="DoingBusinessAsName"
> sql:datatype="varchar" />
> <xs:element name="GeographicAreaID" sql:field="GeographicAreaID"
> sql:datatype="int" />
> <xs:element name="Region" sql:field="Region" sql:datatype="varchar" />
> <xs:element name="District" sql:field="District" sql:datatype="varchar
" />
> <xs:element name="MatrixID" sql:field="MatrixID" sql:datatype="int" />
> <xs:element name="NumberOfEmployees" sql:field="NumberOfEmployees"
> sql:datatype="int" />
> <xs:element name="NumberOfSalesProfessionals"
> sql:field="NumberOfSalesProfessionals" sql:datatype="int" />
> <xs:element name="NumberOfEmployeesPerUPP"
> sql:field="NumberOfEmployeesPerUPP" sql:datatype="varchar" />
> <xs:element name="NumberOfTechProfessionals"
> sql:field="NumberOfTechProfessionals" sql:datatype="int" />
> <xs:element name="OrgHQLocationIndicator"
> sql:field="OrgHQLocationIndicator" sql:datatype="varchar" />
> <xs:element name="NumberOfSalesProfessionalsPerUPP"
> sql:field="NumberOfSalesProfessionalsPerUPP" sql:datatype="varchar" />
> <xs:element name="GlobalPartner" sql:field="GlobalPartner"
> sql:datatype="varchar" />
> <xs:element name="ActiveFlag" sql:field="ActiveFlag"
> sql:datatype="varchar" />
> <xs:element name="NumberOfTechProfessionalsPerUPP"
> sql:field="NumberOfTechProfessionalsPerUPP" sql:datatype="varchar" />
> <xs:element name="MSOrganizationID" sql:field="MSOrganizationID"
> sql:datatype="int" />
> <xs:element name="Seg_1_49_Percent" sql:field="Seg_1_49_Percent"
> sql:datatype="decimal" />
> <xs:element name="Seg_50_999_Percent" sql:field="Seg_50_999_Percent"
> sql:datatype="decimal" />
> <xs:element name="Seg_1000_14999_Percent"
> sql:field="Seg_1000_14999_Percent" sql:datatype="decimal" />
> <xs:element name="Seg_15000_Percent" sql:field="Seg_15000_Percent"
> sql:datatype="decimal" />
> <xs:element name="AddressLine1" sql:field="AddressLine1"
> sql:datatype="varchar" />
> <xs:element name="AddressLine2" sql:field="AddressLine2"
> sql:datatype="varchar" />
> <xs:element name="City" sql:field="City" sql:datatype="varchar" />
> <xs:element name="PostalCode" sql:field="PostalCode"
> sql:datatype="varchar" />
> <xs:element name="StateProvinceId" sql:field="StateProvinceId"
> sql:datatype="varchar" />
> <xs:element name="Phone" sql:field="Phone" sql:datatype="varchar" />
> <xs:element name="SiebelID" sql:field="SiebelID" sql:datatype="int" />
> <xs:element name="StatusID" sql:field="StatusID" sql:datatype="varchar
" />
> <xs:element name="ProfileDueDate" sql:field="ProfileDueDate"
> sql:datatype="datetime" />
> <xs:element name="ManagedBy" sql:field="ManagedBy"
> sql:datatype="varchar" />
> <xs:element name="ParentAccountID" sql:field="ParentAccountID"
> sql:datatype="int" />
> <xs:element name="UPPID" sql:field="UPPID" sql:datatype="int" />
> <xs:element name="LastModifiedBy" sql:field="LastModifiedBy"
> sql:datatype="varchar" />
> <xs:element name="LastModifiedDate" sql:field="LastModifiedDate"
> sql:datatype="datetime" />
> <xs:element name="ParentUPPId" sql:field="ParentUPPId"
> sql:datatype="int" />
> <xs:element name="CustomCampaign" sql:field="CustomCampaign"
> sql:datatype="varchar" />
> <xs:element name="PartnerSalesVertical"
> sql:relation="PartnerSalesVertical"
> sql:relationship=" MicrosoftPartnerProfile_PartnerSalesVert
ical"
> maxOccurs="unbounded">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="SalesVerticalID" sql:field="SalesVerticalID"
> sql:datatype="int" />
> <xs:element name="Checked" sql:field="Checked" sql:datatype="varcha
r"
> />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="PartnerIndustryVertical"
> sql:relation="PartnerIndustryVertical"
> sql:relationship=" MicrosoftPartnerProfile_PartnerIndustryV
ertical"
> maxOccurs="unbounded">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="IndustryVerticalID" sql:field="IndustryVerticalID
"
> sql:datatype="int" />
> <xs:element name="Checked" sql:field="Checked" sql:datatype="varcha
r"
> />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="PartnerGTM" sql:relation="PartnerGTM"
> sql:relationship="MicrosoftPartnerProfile_PartnerGTM" maxOccurs="unbounded
">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="GTMFocusID" sql:field="GTMFocusID"
> sql:datatype="int" />
> <xs:element name="Checked" sql:field="Checked" sql:datatype="varcha
r"
> />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="PartnerCompetency" sql:relation="PartnerCompetency"
> sql:relationship=" MicrosoftPartnerProfile_PartnerCompetenc
y"
> maxOccurs="unbounded">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="CompetencyID" sql:field="CompetencyID"
> sql:datatype="int" />
> <xs:element name="Checked" sql:field="Checked" sql:datatype="varcha
r"
> />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="FormUI" sql:relation="FormUI"
> sql:relationship="MicrosoftPartnerProfile_FormUI" maxOccurs="unbounded">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="CompetencyCheckMode"
> sql:field="CompetencyCheckMode" sql:datatype="varchar" />
> <xs:element name="SpecializationCheckModel"
> sql:field="SpecializationCheckModel" sql:datatype="varchar" />
> <xs:element name="ProductsCheckMode" sql:field="ProductsCheckMode"
> sql:datatype="varchar" />
> <xs:element name="IndustryVerticalsCheckMode"
> sql:field="IndustryVerticalsCheckMode" sql:datatype="varchar" />
> <xs:element name="MBSVerticalsCheckMode"
> sql:field="MBSVerticalsCheckMode" sql:datatype="varchar" />
> <xs:element name="GTMSCheckMode" sql:field="GTMSCheckMode"
> sql:datatype="varchar" />
> <xs:element name="AssessmentsCheckMode"
> sql:field="AssessmentsCheckMode" sql:datatype="varchar" />
> <xs:element name="AnnualBusinessCurrentMode"
> sql:field="AnnualBusinessCurrentMode" sql:datatype="varchar" />
> <xs:element name="BusinessPlanCurrentMode"
> sql:field="BusinessPlanCurrentMode" sql:datatype="varchar" />
> <xs:element name="NavProfileStatus" sql:field="NavProfileStatus"
> sql:datatype="varchar" />
> <xs:element name="NavCoreInformation" sql:field="NavCoreInformation
"
> sql:datatype="varchar" />
> <xs:element name="NavBusinessFocus" sql:field="NavBusinessFocus"
> sql:datatype="varchar" />
> <xs:element name="NavContact" sql:field="NavContact"
> sql:datatype="varchar" />
> <xs:element name="NavBranch" sql:field="NavBranch"
> sql:datatype="varchar" />
> <xs:element name="NavCompetency" sql:field="NavCompetency"
> sql:datatype="varchar" />
> <xs:element name="NavSpecialization" sql:field="NavSpecialization"
> sql:datatype="varchar" />
> <xs:element name="NavIndustryVert" sql:field="NavIndustryVert"
> sql:datatype="varchar" />
> <xs:element name="NavMBSVert" sql:field="NavMBSVert"
> sql:datatype="varchar" />
> <xs:element name="NavRevSummary" sql:field="NavRevSummary"
> sql:datatype="varchar" />
> <xs:element name="NavConditions" sql:field="NavConditions"
> sql:datatype="varchar" />
> <xs:element name="NavRhythm" sql:field="NavRhythm"
> sql:datatype="varchar" />
> <xs:element name="NavCampaigns" sql:field="NavCampaigns"
> sql:datatype="varchar" />
> <xs:element name="NavAssessments" sql:field="NavAssessments"
> sql:datatype="varchar" />
> <xs:element name="NavLinks" sql:field="NavLinks"
> sql:datatype="varchar" />
> <xs:element name="NavProducts" sql:field="NavProducts"
> sql:datatype="varchar" />
> <xs:element name="NavPlanStatus" sql:field="NavPlanStatus"
> sql:datatype="varchar" />
> <xs:element name="NavGoalSummary" sql:field="NavGoalSummary"
> sql:datatype="varchar" />
> <xs:element name="NavInvestments" sql:field="NavInvestments"
> sql:datatype="varchar" />
> <xs:element name="NavSolutionPlan" sql:field="NavSolutionPlan"
> sql:datatype="varchar" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="LinksToOtherDocuments"
> sql:relation="LinksToOtherDocuments"
> sql:relationship=" MicrosoftPartnerProfile_LinksToOtherDocu
ments">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="DocumentUrl" sql:field="DocumentUrl"
> sql:datatype="varchar" />
> <xs:element name="DocumentTitle" sql:field="DocumentTitle"
> sql:datatype="varchar" />
> </xs:sequence>
> </xs:complexType>
> </xs:element>
> <xs:element name="NotesAndConditions" sql:relation="NotesAndConditions
"
> sql:relationship=" MicrosoftPartnerProfile_NotesAndConditio
ns">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="AccountID" sql:field="AccountID"
> sql:datatype="nvarchar" />
> <xs:element name="MeetingFrequencyID" sql:field="MeetingFrequencyID"[/color
]