Showing posts with label tables. Show all posts
Showing posts with label tables. Show all posts

Monday, March 19, 2012

Bug with 'enable identity insert on'

I'm using sp1, tryng to copy from 2005 db to 2005 db, selecting many tables at once, delete target rows on, identity insert ON.

choosing not to optimize for many tables:

Error: 0xC0202009 at Data Flow Task, Destination - table1 [22]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.

An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "The statement has been terminated.".

An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Violation of PRIMARY KEY constraint 'PK_table1'. Cannot insert duplicate key in object 'dbo.table1.".

Error: 0xC0202009 at Data Flow Task, Destination 3 - table2 [226]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.

Etc., for each table

Optimizing for many tables:

Error: 0xC0202009 at {AB2253E6-28B4-4D5A-B843-236F8E53E075}, OLE DB Destination [2]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80004005.

An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "The statement has been terminated.".

An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80004005 Description: "Violation of PRIMARY KEY constraint 'PK_table1'. Cannot insert duplicate key in object 'dbo.table1.".

Information: 0x402090E0 at {AB2253E6-28B4-4D5A-B843-236F8E53E075}, OLE DB Destination [2]: The final commit for the data insertion has ended.

When I drop and recreate the tables manually and set 'identity insert on' it doesn't bring the identity field over AT ALL.

I like that MS has tried to make it easier to move many tables at once by allowing us to set 'enable identity insert' to everything at once, but it doesn't appear to work. ( I've been puzzling over how it could work, anyway...)

Before sp 1, I had to go into each table by clicking the 'edit' button, and it would bring the correct identity value over, but the tables would no longer have the identity property on that field.

I have also tried 'run as a transaction' to no avail...

Well, the error is about PK violation, not about the Identity column definition.

|||Unless the identity column is the PK, in which case you should not have any columns mapped to the identity field in the destination OLE DB component. Leave it blank.|||

The identity column is indeed the PK - NOTE: I didn't design this.

Because the identity column is the PK, and various tables reference the PK, I need to be able to import the actual value.

I did tell it to delete the data first.

If I drop the tables and re-create them with no data, it doesn't bring the identity value over at all, the field auto-numbers.

I seem to be in a no-win situation. Even if I drop all the keys, i still have the problem with not getting the actual identity value inserted.

If the tool is going to allow you to indicate the data should be cleared in the tables first, I think there should be some indication regarding the keys.

I suppose my problem actually lies with the identity value not coming over. I have searched in this forum and found that several others seem to be having the same problem, but have not seen a resolution.

?

|||Are you using "fast load" in the OLE DB destination with "Keep identity" checked?|||

Perhaps I'm misunderstanding the problem but I have just managed to populate a table with an identity column as the PK by loading values into that column.

Here's the code to set it up:

Code Snippet

CREATE DATABASE tmp

GO

USE tmp

GO

CREATE TABLE source (id INT IDENTITY(1,1) PRIMARY key, chr CHAR(1))

GO

INSERT source VALUES ('a')

INSERT source VALUES ('b')

INSERT source VALUES ('c')

CREATE TABLE destination (id INT IDENTITY(1,1) PRIMARY key, chr CHAR(1))

GO

and below is the package that realised it. Let me know what is different in your scenario.

-Jamie

Code Snippet

<?xml version="1.0"?><DTS:Executable xmlns:DTS="www.microsoft.com/SqlServer/Dts" DTS:ExecutableType="MSDTS.Package.1"><DTS:Property DTS:Name="PackageFormatVersion">2</< FONT>DTS:Property><DTS:Property DTS:Name="VersionComments"></< FONT>DTS:Property><DTS:Property DTS:Name="CreatorName">CT\jtbx</< FONT>DTS:Property><DTS:Property DTS:Name="CreatorComputerName">2UA63600NJ</< FONT>DTS:Property><DTS:Property DTS:Name="CreationDate" DTS:DataType="7">3/29/2007 3:25:55 PM</< FONT>DTS:Property><DTS:Property DTS:Name="PackageType">5</< FONT>DTS:Property><DTS:Property DTS:Name="ProtectionLevel">1</< FONT>DTS:Property><DTS:Property DTS:Name="MaxConcurrentExecutables">-1</< FONT>DTS:Property><DTS:Property DTS:Name="PackagePriorityClass">0</< FONT>DTS:Property><DTS:Property DTS:Name="VersionMajor">1</< FONT>DTS:Property><DTS:Property DTS:Name="VersionMinor">0</< FONT>DTS:Property><DTS:Property DTS:Name="VersionBuild">1</< FONT>DTS:Property><DTS:Property DTS:Name="VersionGUID">{2B4A9733-B18D-47EE-A743-7219941EEEB7}</< FONT>DTS:Property><DTS:Property DTS:Name="EnableConfig">0</< FONT>DTS:Property><DTS:Property DTS:Name="CheckpointFileName"></< FONT>DTS:Property><DTS:Property DTS:Name="SaveCheckpoints">0</< FONT>DTS:Property><DTS:Property DTS:Name="CheckpointUsage">0</< FONT>DTS:Property><DTS:Property DTS:Name="SuppressConfigurationWarnings">0</< FONT>DTS:Property>

<DTS:ConnectionManager><DTS:Property DTS:Name="DelayValidation">0</< FONT>DTS:Property><DTS:Property DTS:Name="ObjectName">LocalHost</< FONT>DTS:Property><DTS:Property DTS:Name="DTSID">{711EB6A5-1873-451F-AF3A-8453EC797462}</< FONT>DTS:Property><DTS:Property DTS:Name="Description"></< FONT>DTS:Property><DTS:Property DTS:Name="CreationName">OLEDB</< FONT>DTS:Property><DTS:ObjectData><DTS:ConnectionManager><DTS:Property DTS:Name="Retain">0</< FONT>DTS:Property><DTS:Property DTS:Name="ConnectionString">Data Source=.;Initial Catalog=tmp;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False;</< FONT>DTS:Property></< FONT>DTS:ConnectionManager></< FONT>DTS:ObjectData></< FONT>DTS:ConnectionManager>

<DTS:PackageVariable><DTS:Property DTS:Name="PackageVariableValue" DTS:DataType="8"><Package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dwd="http://schemas.microsoft.com/DataWarehouse/Designer/1.0"><dwd:DtsControlFlowDiagram><dwd:Layout><dds>

<diagram fontclsid="{0BE35203-8F91-11CE-9DE3-00AA004BB851}" mouseiconclsid="{0BE35204-8F91-11CE-9DE3-00AA004BB851}" defaultlayout="Microsoft.DataWarehouse.Layout.GraphLayout" defaultlineroute="Microsoft.DataWarehouse.Layout.GraphLayout" version="7" nextobject="4" scale="100" pagebreakanchorx="0" pagebreakanchory="0" pagebreaksizex="0" pagebreaksizey="0" scrollleft="0" scrolltop="0" gridx="150" gridy="150" marginx="1000" marginy="1000" zoom="100" x="20717" y="17568" backcolor="15334399" defaultpersistence="2" PrintPageNumbersMode="3" PrintMarginTop="0" PrintMarginBottom="635" PrintMarginLeft="0" PrintMarginRight="0" marqueeselectionmode="1" mousepointer="0" snaptogrid="0" autotypeannotation="1" showscrollbars="0" viewpagebreaks="0" donotforceconnectorsbehindshapes="1" backpictureclsid="{00000000-0000-0000-0000-000000000000}">

<font>

<ddsxmlobjectstreamwrapper binary="01010000900180380100065461686f6d61" />

</font>

<mouseicon>

<ddsxmlobjectstreamwrapper binary="6c74000000000000" />

</mouseicon>

</diagram>

<layoutmanager>

<ddsxmlobj />

</layoutmanager>

<ddscontrol controlprogid="DdsShapes.DdsObjectManagedBridge.1" tooltip="Validation warnings occurred." left="0" top="0" logicalid="3" controlid="3" masterid="0" hint1="0" hint2="0" width="3598" height="1164" noresize="0" nomove="0" nodefaultattachpoints="0" autodrag="1" usedefaultiddshape="1" selectable="1" showselectionhandles="1" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0">

<control>

<ddsxmlobjectstreaminitwrapper binary="000800000e0e00008c040000" />

</control>

<layoutobject>

<ddsxmlobj>

<property name="LogicalObject" value="{D1234F40-926A-4975-86F0-EFC71316CEB6}" vartype="8" />

<property name="ShowConnectorSource" value="0" vartype="2" />

</ddsxmlobj>

</layoutobject>

<shape groupshapeid="0" groupnode="0" />

</ddscontrol>

</dds></dwd:Layout></dwd:DtsControlFlowDiagram></Package></< FONT>DTS:Property><DTS:Property DTS:Name="Namespace">dts-designer-1.0</< FONT>DTS:Property><DTS:Property DTS:Name="ObjectName">{CBA6818F-FBB0-4EE8-A1BF-AD304660C52A}</< FONT>DTS:Property><DTS:Property DTS:Name="DTSID">{F740740D-718C-47DB-9D17-E2071E8A5DF3}</< FONT>DTS:Property><DTS:Property DTS:Name="Description"></< FONT>DTS:Property><DTS:Property DTS:Name="CreationName"></< FONT>DTS:Property></< FONT>DTS:PackageVariable>

<DTS:PackageVariable><DTS:Property DTS:Name="PackageVariableValue" DTS:DataType="8"><TaskHost xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dwd="http://schemas.microsoft.com/DataWarehouse/Designer/1.0"><dwd:DtsDataFlowDiagram><dwd:BoundingTop>3863</dwd:BoundingTop><dwd:Layout><dds>

<diagram fontclsid="{0BE35203-8F91-11CE-9DE3-00AA004BB851}" mouseiconclsid="{0BE35204-8F91-11CE-9DE3-00AA004BB851}" defaultlayout="Microsoft.DataWarehouse.Layout.GraphLayout" defaultlineroute="Microsoft.DataWarehouse.Layout.GraphLayout" version="7" nextobject="7" scale="100" pagebreakanchorx="0" pagebreakanchory="0" pagebreaksizex="0" pagebreaksizey="0" scrollleft="0" scrolltop="0" gridx="150" gridy="150" marginx="1000" marginy="1000" zoom="100" x="18071" y="16642" backcolor="15334399" defaultpersistence="2" PrintPageNumbersMode="3" PrintMarginTop="0" PrintMarginBottom="635" PrintMarginLeft="0" PrintMarginRight="0" marqueeselectionmode="1" mousepointer="0" snaptogrid="0" autotypeannotation="1" showscrollbars="0" viewpagebreaks="0" donotforceconnectorsbehindshapes="0" backpictureclsid="{00000000-0000-0000-0000-000000000000}">

<font>

<ddsxmlobjectstreamwrapper binary="01010000900180380100065461686f6d61" />

</font>

<mouseicon>

<ddsxmlobjectstreamwrapper binary="6c74000000000000" />

</mouseicon>

</diagram>

<layoutmanager>

<ddsxmlobj />

</layoutmanager>

<ddscontrol controlprogid="DdsShapes.DdsObjectManagedBridge.1" tooltip="OLE DB Source" left="11298" top="3863" logicalid="4" controlid="4" masterid="0" hint1="0" hint2="0" width="3598" height="1164" noresize="0" nomove="0" nodefaultattachpoints="0" autodrag="1" usedefaultiddshape="1" selectable="1" showselectionhandles="1" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0">

<control>

<ddsxmlobjectstreaminitwrapper binary="000800000e0e00008c040000" />

</control>

<layoutobject>

<ddsxmlobj>

<property name="LogicalObject" value="{D1234F40-926A-4975-86F0-EFC71316CEB6}/components/1" vartype="8" />

<property name="ShowConnectorSource" value="0" vartype="2" />

</ddsxmlobj>

</layoutobject>

<shape groupshapeid="0" groupnode="0" />

</ddscontrol>

<ddscontrol controlprogid="DdsShapes.DdsObjectManagedBridge.1" tooltip="OLE DB Destination" left="12700" top="6509" logicalid="5" controlid="5" masterid="0" hint1="0" hint2="0" width="3598" height="1164" noresize="0" nomove="0" nodefaultattachpoints="0" autodrag="1" usedefaultiddshape="1" selectable="1" showselectionhandles="1" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0">

<control>

<ddsxmlobjectstreaminitwrapper binary="000800000e0e00008c040000" />

</control>

<layoutobject>

<ddsxmlobj>

<property name="LogicalObject" value="{D1234F40-926A-4975-86F0-EFC71316CEB6}/components/52" vartype="8" />

<property name="ShowConnectorSource" value="0" vartype="2" />

</ddsxmlobj>

</layoutobject>

<shape groupshapeid="0" groupnode="0" />

</ddscontrol>

<ddscontrol controlprogid="MSDDS.Polyline" left="12698" top="4628" logicalid="6" controlid="6" masterid="0" hint1="0" hint2="0" width="2201" height="2381" noresize="0" nomove="0" nodefaultattachpoints="1" autodrag="0" usedefaultiddshape="0" selectable="1" showselectionhandles="0" allownudging="1" isannotation="0" dontautolayout="0" groupcollapsed="0" tabstop="1" visible="1" snaptogrid="0">

<control>

<ddsxmlobj>

<polyline endtypedst="3" endtypesrc="1" usercolor="32768" linestyle="0" linerender="1" customendtypedstid="0" customendtypesrcid="0" adornsvisible="1" />

</ddsxmlobj>

</control>

<layoutobject>

<ddsxmlobj>

<property name="LogicalObject" value="{D1234F40-926A-4975-86F0-EFC71316CEB6}/paths/69" vartype="8" />

<property name="Virtual" value="0" vartype="11" />

<property name="VisibleAP" value="0" vartype="3" />

</ddsxmlobj>

</layoutobject>

<connector lineroutestyle="Microsoft.DataWarehouse.Layout.GraphLayout" sourceid="4" destid="5" sourceattachpoint="7" destattachpoint="6" segmenteditmode="0" bendpointeditmode="0" bendpointvisibility="2" relatedid="0" virtual="0">

<point x="13097" y="5027" />

<point x="13097" y="5768" />

<point x="14499" y="5768" />

<point x="14499" y="6509" />

</connector>

</ddscontrol>

</dds></dwd:Layout></dwd:DtsDataFlowDiagram><dwd:DtsComponentDesignerPropertiesList><dwd:DtsComponentDesignTimeProperty><dwd:key xsi:type="xsd:string">52 DataSourceViewID</dwd:key></dwd:DtsComponentDesignTimeProperty><dwd:DtsComponentDesignTimeProperty><dwd:key xsi:type="xsd:string">1 DataSourceViewID</dwd:key></dwd:DtsComponentDesignTimeProperty><dwd:DtsComponentDesignTimeProperty><dwd:key xsi:type="xsd:string">52 TableInfoObjectType</dwd:key><dwd:value xsi:type="xsd:string">Table</dwd:value></dwd:DtsComponentDesignTimeProperty><dwd:DtsComponentDesignTimeProperty><dwd:key xsi:type="xsd:string">1 TableInfoObjectType</dwd:key><dwd:value xsi:type="xsd:string">Table</dwd:value></dwd:DtsComponentDesignTimeProperty></dwd:DtsComponentDesignerPropertiesList></TaskHost></< FONT>DTS:Property><DTS:Property DTS:Name="Namespace">dts-designer-1.0</< FONT>DTS:Property><DTS:Property DTS:Name="ObjectName">{D1234F40-926A-4975-86F0-EFC71316CEB6}</< FONT>DTS:Property><DTS:Property DTS:Name="DTSID">{59998195-8E74-4AB7-9A98-206CCB534639}</< FONT>DTS:Property><DTS:Property DTS:Name="Description"></< FONT>DTS:Property><DTS:Property DTS:Name="CreationName"></< FONT>DTS:Property></< FONT>DTS:PackageVariable>

<DTS:PackageVariable><DTS:Property DTS:Name="PackageVariableValue" DTS:DataType="8"><PipelinePath xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dwd="http://schemas.microsoft.com/DataWarehouse/Designer/1.0"><dwd:DestinationName>OLE DB Destination Input</dwd:DestinationName><dwd:SourceName>OLE DB Source Output</dwd:SourceName></PipelinePath></< FONT>DTS:Property><DTS:Property DTS:Name="Namespace">dts-designer-1.0</< FONT>DTS:Property><DTS:Property DTS:Name="ObjectName">{D1234F40-926A-4975-86F0-EFC71316CEB6}-69</< FONT>DTS:Property><DTS:Property DTS:Name="DTSID">{CF4C1E95-3336-4ED4-A60C-F4219105D5DE}</< FONT>DTS:Property><DTS:Property DTS:Name="Description"></< FONT>DTS:Property><DTS:Property DTS:Name="CreationName"></< FONT>DTS:Property></< FONT>DTS:PackageVariable><DTS:Property DTS:Name="ForceExecValue">0</< FONT>DTS:Property><DTS:Property DTS:Name="ExecValue" DTS:DataType="3">0</< FONT>DTS:Property><DTS:Property DTS:Name="ForceExecutionResult">-1</< FONT>DTS:Property><DTS:Property DTS:Name="Disabled">0</< FONT>DTS:Property><DTS:Property DTS:Name="FailPackageOnFailure">0</< FONT>DTS:Property><DTS:Property DTS:Name="FailParentOnFailure">0</< FONT>DTS:Property><DTS:Property DTS:Name="MaxErrorCount">1</< FONT>DTS:Property><DTS:Property DTS:Name="ISOLevel">1048576</< FONT>DTS:Property><DTS:Property DTS:Name="LocaleID">1033</< FONT>DTS:Property><DTS:Property DTS:Name="TransactionOption">1</< FONT>DTS:Property><DTS:Property DTS:Name="DelayValidation">0</< FONT>DTS:Property>

<DTS:LoggingOptions><DTS:Property DTS:Name="LoggingMode">0</< FONT>DTS:Property><DTS:Property DTS:Name="FilterKind">1</< FONT>DTS:Property><DTS:Property DTS:Name="EventFilter" DTS:DataType="8"></< FONT>DTS:Property></< FONT>DTS:LoggingOptions>

<DTS:Executable DTS:ExecutableType="{C3BF9DC1-4715-4694-936F-D3CFDA9E42C5}"><DTS:Property DTS:Name="ExecutionLocation">0</< FONT>DTS:Property><DTS:Property DTS:Name="ExecutionAddress"></< FONT>DTS:Property><DTS:Property DTS:Name="TaskContact"></< FONT>DTS:Property><DTS:Property DTS:Name="ForceExecValue">0</< FONT>DTS:Property><DTS:Property DTS:Name="ExecValue" DTS:DataType="3">0</< FONT>DTS:Property><DTS:Property DTS:Name="ForceExecutionResult">-1</< FONT>DTS:Property><DTS:Property DTS:Name="Disabled">0</< FONT>DTS:Property><DTS:Property DTS:Name="FailPackageOnFailure">0</< FONT>DTS:Property><DTS:Property DTS:Name="FailParentOnFailure">0</< FONT>DTS:Property><DTS:Property DTS:Name="MaxErrorCount">1</< FONT>DTS:Property><DTS:Property DTS:Name="ISOLevel">1048576</< FONT>DTS:Property><DTS:Property DTS:Name="LocaleID">-1</< FONT>DTS:Property><DTS:Property DTS:Name="TransactionOption">1</< FONT>DTS:Property><DTS:Property DTS:Name="DelayValidation">0</< FONT>DTS:Property>

<DTS:LoggingOptions><DTS:Property DTS:Name="LoggingMode">0</< FONT>DTS:Property><DTS:Property DTS:Name="FilterKind">1</< FONT>DTS:Property><DTS:Property DTS:Name="EventFilter" DTS:DataType="8"></< FONT>DTS:Property></< FONT>DTS:LoggingOptions><DTS:Property DTS:Name="ObjectName">Data Flow Task</< FONT>DTS:Property><DTS:Property DTS:Name="DTSID">{D1234F40-926A-4975-86F0-EFC71316CEB6}</< FONT>DTS:Property><DTS:Property DTS:Name="Description">Data Flow Task</< FONT>DTS:Property><DTS:Property DTS:Name="CreationName">{C3BF9DC1-4715-4694-936F-D3CFDA9E42C5}</< FONT>DTS:Property><DTS:Property DTS:Name="DisableEventHandlers">0</< FONT>DTS:Property><DTS:ObjectData><pipeline id="0" name="pipelineXml" description="pipelineXml" defaultBufferMaxRows="10000" engineThreads="5" defaultBufferSize="10485760" BLOBTempStoragePath="" bufferTempStoragePath="" runInOptimizedMode="true">

<components>

<component id="1" name="OLE DB Source" componentClassID="{2C0A8BE5-1EDC-4353-A0EF-B778599C65A0}" description="OLE DB Source" localeId="-1" usesDispositions="true" validateExternalMetadata="True" version="7" pipelineVersion="0" contactInfo="OLE DB Source;Microsoft Corporation;Microsoft SqlServer v9; (C) 2005 Microsoft Corporation; All Rights Reserved; http://www.microsoft.com/sql/support;7">

<properties>

<property id="2" name="CommandTimeout" dataType="System.Int32" state="default" isArray="false" description="The number of seconds before a command times out. A value of 0 indicates an infinite time-out." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">0</< FONT>property>

<property id="3" name="OpenRowset" dataType="System.String" state="default" isArray="false" description="Specifies the name of the database object used to open a rowset." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">[dbo].[source]</< FONT>property>

<property id="4" name="OpenRowsetVariable" dataType="System.String" state="default" isArray="false" description="Specifies the variable that contains the name of the database object used to open a rowset." typeConverter="" UITypeEditor="" containsID="false" expressionType="None"></< FONT>property>

<property id="5" name="SqlCommand" dataType="System.String" state="default" isArray="false" description="The SQL command to be executed." typeConverter="" UITypeEditor="Microsoft.DataTransformationServices.Controls.ModalMultilineStringEditor, Microsoft.DataTransformationServices.Controls, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" containsID="false" expressionType="None"></< FONT>property>

<property id="6" name="SqlCommandVariable" dataType="System.String" state="default" isArray="false" description="The variable that contains the SQL command to be executed." typeConverter="" UITypeEditor="" containsID="false" expressionType="None"></< FONT>property>

<property id="7" name="DefaultCodePage" dataType="System.Int32" state="default" isArray="false" description="Specifies the column code page to use when code page information is unavailable from the data source." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">1252</< FONT>property>

<property id="8" name="AlwaysUseDefaultCodePage" dataType="System.Boolean" state="default" isArray="false" description="Forces the use of the DefaultCodePage property value when describing character data." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">false</< FONT>property>

<property id="9" name="AccessMode" dataType="System.Int32" state="default" isArray="false" description="Specifies the mode used to access the database." typeConverter="AccessMode" UITypeEditor="" containsID="false" expressionType="None">0</< FONT>property>

<property id="15" name="ParameterMapping" dataType="System.String" state="default" isArray="false" description="The mappings between the parameters in the SQL command and variables." typeConverter="" UITypeEditor="" containsID="false" expressionType="None"></< FONT>property></< FONT>properties>

<connections>

<connection id="10" name="OleDbConnection" description="The OLE DB runtime connection used to access the database." connectionManagerID="{711EB6A5-1873-451F-AF3A-8453EC797462}"/></< FONT>connections>

<outputs>

<output id="11" name="OLE DB Source Output" description="" exclusionGroup="0" synchronousInputId="0" deleteOutputOnPathDetached="false" hasSideEffects="false" dangling="false" isErrorOut="false" isSorted="false" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed"><outputColumns>

<outputColumn id="47" name="id" description="" lineageId="47" precision="0" scale="0" length="0" dataType="i4" codePage="0" sortKeyPosition="0" comparisonFlags="0" specialFlags="0" errorOrTruncationOperation="Conversion" errorRowDisposition="FailComponent" truncationRowDisposition="FailComponent" externalMetadataColumnId="46"/>

<outputColumn id="50" name="chr" description="" lineageId="50" precision="0" scale="0" length="1" dataType="str" codePage="1252" sortKeyPosition="0" comparisonFlags="0" specialFlags="0" errorOrTruncationOperation="Conversion" errorRowDisposition="FailComponent" truncationRowDisposition="FailComponent" externalMetadataColumnId="49"/></< FONT>outputColumns><externalMetadataColumns isUsed="True">

<externalMetadataColumn id="46" name="id" description="" precision="0" scale="0" length="0" dataType="i4" codePage="0"/>

<externalMetadataColumn id="49" name="chr" description="" precision="0" scale="0" length="1" dataType="str" codePage="1252"/></< FONT>externalMetadataColumns></< FONT>output>

<output id="12" name="OLE DB Source Error Output" description="" exclusionGroup="0" synchronousInputId="0" deleteOutputOnPathDetached="false" hasSideEffects="false" dangling="false" isErrorOut="true" isSorted="false" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed"><outputColumns>

<outputColumn id="48" name="id" description="" lineageId="48" precision="0" scale="0" length="0" dataType="i4" codePage="0" sortKeyPosition="0" comparisonFlags="0" specialFlags="0" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="0"/>

<outputColumn id="51" name="chr" description="" lineageId="51" precision="0" scale="0" length="1" dataType="str" codePage="1252" sortKeyPosition="0" comparisonFlags="0" specialFlags="0" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="0"/>

<outputColumn id="13" name="ErrorCode" description="" lineageId="13" precision="0" scale="0" length="0" dataType="i4" codePage="0" sortKeyPosition="0" comparisonFlags="0" specialFlags="1" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="0"/>

<outputColumn id="14" name="ErrorColumn" description="" lineageId="14" precision="0" scale="0" length="0" dataType="i4" codePage="0" sortKeyPosition="0" comparisonFlags="0" specialFlags="2" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="0"/></< FONT>outputColumns><externalMetadataColumns isUsed="False"/></< FONT>output>

</< FONT>outputs>

</< FONT>component>

<component id="52" name="OLE DB Destination" componentClassID="{E2568105-9550-4F71-A638-B7FE42E66922}" description="OLE DB Destination" localeId="-1" usesDispositions="true" validateExternalMetadata="True" version="4" pipelineVersion="0" contactInfo="OLE DB Destination;Microsoft Corporation;Microsoft SqlServer v9; (C) 2005 Microsoft Corporation; All Rights Reserved; http://www.microsoft.com/sql/support;4">

<properties>

<property id="53" name="CommandTimeout" dataType="System.Int32" state="default" isArray="false" description="The number of seconds before a command times out. A value of 0 indicates an infinite time-out." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">0</< FONT>property>

<property id="54" name="OpenRowset" dataType="System.String" state="default" isArray="false" description="Specifies the name of the database object used to open a rowset." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">[dbo].[destination]</< FONT>property>

<property id="55" name="OpenRowsetVariable" dataType="System.String" state="default" isArray="false" description="Specifies the variable that contains the name of the database object used to open a rowset." typeConverter="" UITypeEditor="" containsID="false" expressionType="None"></< FONT>property>

<property id="56" name="SqlCommand" dataType="System.String" state="default" isArray="false" description="The SQL command to be executed." typeConverter="" UITypeEditor="Microsoft.DataTransformationServices.Controls.ModalMultilineStringEditor, Microsoft.DataTransformationServices.Controls, Version=9.0.242.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" containsID="false" expressionType="None"></< FONT>property>

<property id="57" name="DefaultCodePage" dataType="System.Int32" state="default" isArray="false" description="Specifies the column code page to use when code page information is unavailable from the data source." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">1252</< FONT>property>

<property id="58" name="AlwaysUseDefaultCodePage" dataType="System.Boolean" state="default" isArray="false" description="Forces the use of the DefaultCodePage property value when describing character data." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">false</< FONT>property>

<property id="59" name="AccessMode" dataType="System.Int32" state="default" isArray="false" description="Specifies the mode used to access the database." typeConverter="AccessMode" UITypeEditor="" containsID="false" expressionType="None">3</< FONT>property>

<property id="61" name="FastLoadKeepIdentity" dataType="System.Boolean" state="default" isArray="false" description="Indicates whether the values supplied for identity columns will be copied to the destination. If false, values for identity columns will be auto-generated at the destination. Applies only if fast load is turned on." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">true</< FONT>property>

<property id="62" name="FastLoadKeepNulls" dataType="System.Boolean" state="default" isArray="false" description="Indicates whether the columns containing null will have null inserted in the destination. If false, columns containing null will have their default values inserted at the destinaton. Applies only if fast load is turned on." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">false</< FONT>property>

<property id="63" name="FastLoadOptions" dataType="System.String" state="default" isArray="false" description="Specifies options to be used with fast load. Applies only if fast load is turned on." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">TABLOCK,CHECK_CONSTRAINTS</< FONT>property>

<property id="64" name="FastLoadMaxInsertCommitSize" dataType="System.Int32" state="default" isArray="false" description="Specifies when commits are issued during data insertion. A value of 0 specifies that one commit will be issued at the end of data insertion. Applies only if fast load is turned on." typeConverter="" UITypeEditor="" containsID="false" expressionType="None">0</< FONT>property></< FONT>properties>

<connections>

<connection id="60" name="OleDbConnection" description="The OLE DB runtime connection used to access the database." connectionManagerID="{711EB6A5-1873-451F-AF3A-8453EC797462}"/></< FONT>connections>

<inputs>

<input id="65" name="OLE DB Destination Input" description="" hasSideEffects="true" dangling="false" errorOrTruncationOperation="Insert" errorRowDisposition="FailComponent" truncationRowDisposition="NotUsed"><inputColumns>

<inputColumn id="89" name="" description="" lineageId="47" usageType="readOnly" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="87"/>

<inputColumn id="90" name="" description="" lineageId="50" usageType="readOnly" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="88"/>

</< FONT>inputColumns><externalMetadataColumns isUsed="True">

<externalMetadataColumn id="87" name="id" description="" precision="0" scale="0" length="0" dataType="i4" codePage="0"/>

<externalMetadataColumn id="88" name="chr" description="" precision="0" scale="0" length="1" dataType="str" codePage="1252"/></< FONT>externalMetadataColumns></< FONT>input>

</< FONT>inputs>

<outputs>

<output id="66" name="OLE DB Destination Error Output" description="" exclusionGroup="1" synchronousInputId="65" deleteOutputOnPathDetached="false" hasSideEffects="false" dangling="false" isErrorOut="true" isSorted="false" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed"><outputColumns>

<outputColumn id="67" name="ErrorCode" description="" lineageId="67" precision="0" scale="0" length="0" dataType="i4" codePage="0" sortKeyPosition="0" comparisonFlags="0" specialFlags="1" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="0"/>

<outputColumn id="68" name="ErrorColumn" description="" lineageId="68" precision="0" scale="0" length="0" dataType="i4" codePage="0" sortKeyPosition="0" comparisonFlags="0" specialFlags="2" errorOrTruncationOperation="" errorRowDisposition="NotUsed" truncationRowDisposition="NotUsed" externalMetadataColumnId="0"/></< FONT>outputColumns><externalMetadataColumns isUsed="False"/></< FONT>output>

</< FONT>outputs>

</< FONT>component>

</< FONT>components>

<paths>

<path id="69" name="OLE DB Source Output" description="" startId="11" endId="65"/>

</< FONT>paths></< FONT>pipeline></< FONT>DTS:ObjectData></< FONT>DTS:Executable><DTS:Property DTS:Name="ObjectName">Package9</< FONT>DTS:Property><DTS:Property DTS:Name="DTSID">{CBA6818F-FBB0-4EE8-A1BF-AD304660C52A}</< FONT>DTS:Property><DTS:Property DTS:Name="Description"></< FONT>DTS:Property><DTS:Property DTS:Name="CreationName">MSDTS.Package.1</< FONT>DTS:Property><DTS:Property DTS:Name="DisableEventHandlers">0</< FONT>DTS:Property></< FONT>DTS:Executable>

Bug or Feature?

When upgrading a database from MSDE to Visual Studio 2005 Express, I've noticed that the system tables in the MSDB database don't get upgraded. For example, the SYSSCHEDULES table doesn't get added. Is this by design or a bug?

-Doug

Belatedly moving this thread to the Express forum for an answer.|||

Given that there is no SQL Agent support in Express this may well be by design

|||

Hi Doug,

This has been addressed in SP1, which you can get from http://msdn.microsoft.com/vstudio/express/sql/download.

Regards,

Mike Wachal
SQL Express team

Mark the best posts as Answers!

|||I did find a fix to this problem. If I run the INSTMSDB.SQL script from the install directory on the updgraded database, it will install all of the new MSDB system tables.

Thursday, March 8, 2012

Bug in indexed view?

We use SQL server 2000 sp3 database server in Windows 2000 Advanced server O
S.
In production environment, one of the fact tables in our datamart has over
150 mil rows. A indexed view is built upon this fact table for reporting
purposes.
The problem is that when queried for the same criteria, the indexed view
returns different result than the underlying table. This problem has occured
twice in a single month. The problem was resolved upon rebuilding the indexe
d
view.
FYI. We have lots of data inserts as part of overnight batch process.
Queries:
--
SELECT sum(value)
FROM <<FactTableName>> (NOLOCK)
WHERE portfolioid = 100
and cob = '30 Jan 2006'
OPTION (EXPAND VIEWS)
SELECT sum(value)
FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
WHERE portfolioid = 100
and cob = '30 Jan 2006'
Any help on this is appreciated.
--
CheersHi
Does the view based on a single table?
"Space_AD" <SpaceAD@.discussions.microsoft.com> wrote in message
news:43DC2E60-C5E6-4B31-8B2F-893453A3C14C@.microsoft.com...
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced server
> OS.
> In production environment, one of the fact tables in our datamart has over
> 150 mil rows. A indexed view is built upon this fact table for reporting
> purposes.
> The problem is that when queried for the same criteria, the indexed view
> returns different result than the underlying table. This problem has
> occured
> twice in a single month. The problem was resolved upon rebuilding the
> indexed
> view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
> --
> Cheers
>|||Yes, the indexed view is based on a single table.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW <<view>> WITH SCHEMABINDING
AS
SELECT <<col1>>
, <<col2>>
, <<col3>>
, <<col4>>
, <<col5>>
, <<col6>>
, SUM(<<numeric col1>> )
, SUM(<<numeric col2>> )
, COUNT_BIG(*)
FROM dbo.<<facttable>> AS pv
WHERE Balance = 1
GROUP
BY <<col1>>
, <<col2>>
, <<col3>>
, <<col4>>
, <<col5>>
, <<col6>>
GO
SET
ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_Y
IELDS_NULL,ARITHABORT,QUOTED_IDENTIF
IER,ANSI_NULLS
ON
SET NUMERIC_ROUNDABORT OFF
GO
if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
id = object_id(N'[dbo].[<<view>>]'))
DROP INDEX [dbo].[<<view>>].[<<idxname>>]
GO
CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<view>
>] (
<<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>> )
GO
Thanks,
Arun|||Hi!
Try remove "nolock" hint from your queries.
Micle.
"Space_AD" <SpaceAD@.discussions.microsoft.com> wrote in message
news:43DC2E60-C5E6-4B31-8B2F-893453A3C14C@.microsoft.com...
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced server
> OS.
> In production environment, one of the fact tables in our datamart has over
> 150 mil rows. A indexed view is built upon this fact table for reporting
> purposes.
> The problem is that when queried for the same criteria, the indexed view
> returns different result than the underlying table. This problem has
> occured
> twice in a single month. The problem was resolved upon rebuilding the
> indexed
> view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
> --
> Cheers
>|||I have already tried it. It does not do any dirty reads..
FYI.. The bug has occured again today.
Cheers,
Arun|||CREATE CI on col1 and col2 ONLY
<arun.ns@.gmail.com> wrote in message
news:1138796568.572051.8640@.g49g2000cwa.googlegroups.com...
> Yes, the indexed view is based on a single table.
>
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> CREATE VIEW <<view>> WITH SCHEMABINDING
> AS
> SELECT <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> , SUM(<<numeric col1>> )
> , SUM(<<numeric col2>> )
> , COUNT_BIG(*)
> FROM dbo.<<facttable>> AS pv
> WHERE Balance = 1
> GROUP
> BY <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> GO
>
> SET
> ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_Y
IELDS_NULL,ARITHABORT,QUOTED_IDENT
IFIER,ANSI_NULLS
> ON
> SET NUMERIC_ROUNDABORT OFF
> GO
> if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
> id = object_id(N'[dbo].[<<view>>]'))
> DROP INDEX [dbo].[<<view>>].[<<idxname>>]
> GO
> CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<vie
w>>] (
> <<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>> )
> GO
> Thanks,
> Arun
>|||Space_AD wrote:
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced
> server OS.
> In production environment, one of the fact tables in our datamart has
> over 150 mil rows. A indexed view is built upon this fact table for
> reporting purposes.
> The problem is that when queried for the same criteria, the indexed
> view returns different result than the underlying table. This problem
> has occured twice in a single month. The problem was resolved upon
> rebuilding the indexed view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
And there is no additional criterium that limits records in the view?
Could your problem be caused by NULL values? Just some 0.01 cents...
robert|||The value column is not nullable.
Cheers,
Space_AD
"Robert Klemme" wrote:

> Space_AD wrote:
> And there is no additional criterium that limits records in the view?
> Could your problem be caused by NULL values? Just some 0.01 cents...
> robert
>|||We found that this problem occured after some deadlock in the underlying
tables.
But not sure how dead locks affect the indexed view .
Cheers,
Space_AD
"arun.ns@.gmail.com" wrote:

> Yes, the indexed view is based on a single table.
>
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> CREATE VIEW <<view>> WITH SCHEMABINDING
> AS
> SELECT <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> , SUM(<<numeric col1>> )
> , SUM(<<numeric col2>> )
> , COUNT_BIG(*)
> FROM dbo.<<facttable>> AS pv
> WHERE Balance = 1
> GROUP
> BY <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> GO
>
> SET
> ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_Y
IELDS_NULL,ARITHABORT,QUOTED_IDENT
IFIER,ANSI_NULLS
> ON
> SET NUMERIC_ROUNDABORT OFF
> GO
> if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
> id = object_id(N'[dbo].[<<view>>]'))
> DROP INDEX [dbo].[<<view>>].[<<idxname>>]
> GO
> CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<vie
w>>] (
> <<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>> )
> GO
> Thanks,
> Arun
>|||we have found that this problem occured just after a deadlocking scenario
involving the underlying table.
But not sure why this deadlock is causing incorrect data in indexed view.
Cheers,
Space_AD
"Space_AD" wrote:
[vbcol=seagreen]
> The value column is not nullable.
> --
> Cheers,
> Space_AD
>
> "Robert Klemme" wrote:
>

Bug in indexed view?

We use SQL server 2000 sp3 database server in Windows 2000 Advanced server OS.
In production environment, one of the fact tables in our datamart has over
150 mil rows. A indexed view is built upon this fact table for reporting
purposes.
The problem is that when queried for the same criteria, the indexed view
returns different result than the underlying table. This problem has occured
twice in a single month. The problem was resolved upon rebuilding the indexed
view.
FYI. We have lots of data inserts as part of overnight batch process.
Queries:
SELECT sum(value)
FROM <<FactTableName>> (NOLOCK)
WHERE portfolioid = 100
and cob = '30 Jan 2006'
OPTION (EXPAND VIEWS)
SELECT sum(value)
FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
WHERE portfolioid = 100
and cob = '30 Jan 2006'
Any help on this is appreciated.
Cheers
Hi
Does the view based on a single table?
"Space_AD" <SpaceAD@.discussions.microsoft.com> wrote in message
news:43DC2E60-C5E6-4B31-8B2F-893453A3C14C@.microsoft.com...
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced server
> OS.
> In production environment, one of the fact tables in our datamart has over
> 150 mil rows. A indexed view is built upon this fact table for reporting
> purposes.
> The problem is that when queried for the same criteria, the indexed view
> returns different result than the underlying table. This problem has
> occured
> twice in a single month. The problem was resolved upon rebuilding the
> indexed
> view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
> --
> Cheers
>
|||Yes, the indexed view is based on a single table.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW <<view>> WITH SCHEMABINDING
AS
SELECT<<col1>>
,<<col2>>
,<<col3>>
,<<col4>>
,<<col5>>
,<<col6>>
,SUM(<<numeric col1>>)
,SUM(<<numeric col2>>)
,COUNT_BIG(*)
FROM dbo.<<facttable>>AS pv
WHEREBalance = 1
GROUP
BY <<col1>>
,<<col2>>
,<<col3>>
,<<col4>>
,<<col5>>
,<<col6>>
GO
SET
ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL ,ARITHABORT,QUOTED_IDENTIFIER,ANSI_NULLS
ON
SET NUMERIC_ROUNDABORT OFF
GO
if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
id = object_id(N'[dbo].[<<view>>]'))
DROP INDEX [dbo].[<<view>>].[<<idxname>>]
GO
CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<view>>] (
<<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>>)
GO
Thanks,
Arun
|||Hi!
Try remove "nolock" hint from your queries.
Micle.
"Space_AD" <SpaceAD@.discussions.microsoft.com> wrote in message
news:43DC2E60-C5E6-4B31-8B2F-893453A3C14C@.microsoft.com...
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced server
> OS.
> In production environment, one of the fact tables in our datamart has over
> 150 mil rows. A indexed view is built upon this fact table for reporting
> purposes.
> The problem is that when queried for the same criteria, the indexed view
> returns different result than the underlying table. This problem has
> occured
> twice in a single month. The problem was resolved upon rebuilding the
> indexed
> view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
> --
> Cheers
>
|||I have already tried it. It does not do any dirty reads..
FYI.. The bug has occured again today.
Cheers,
Arun
|||CREATE CI on col1 and col2 ONLY
<arun.ns@.gmail.com> wrote in message
news:1138796568.572051.8640@.g49g2000cwa.googlegrou ps.com...
> Yes, the indexed view is based on a single table.
>
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> CREATE VIEW <<view>> WITH SCHEMABINDING
> AS
> SELECT <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> , SUM(<<numeric col1>>)
> , SUM(<<numeric col2>>)
> , COUNT_BIG(*)
> FROM dbo.<<facttable>> AS pv
> WHERE Balance = 1
> GROUP
> BY <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> GO
>
> SET
> ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL ,ARITHABORT,QUOTED_IDENTIFIER,ANSI_NULLS
> ON
> SET NUMERIC_ROUNDABORT OFF
> GO
> if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
> id = object_id(N'[dbo].[<<view>>]'))
> DROP INDEX [dbo].[<<view>>].[<<idxname>>]
> GO
> CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<view>>] (
> <<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>>)
> GO
> Thanks,
> Arun
>
|||Space_AD wrote:
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced
> server OS.
> In production environment, one of the fact tables in our datamart has
> over 150 mil rows. A indexed view is built upon this fact table for
> reporting purposes.
> The problem is that when queried for the same criteria, the indexed
> view returns different result than the underlying table. This problem
> has occured twice in a single month. The problem was resolved upon
> rebuilding the indexed view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
And there is no additional criterium that limits records in the view?
Could your problem be caused by NULL values? Just some 0.01 cents...
robert
|||The value column is not nullable.
Cheers,
Space_AD
"Robert Klemme" wrote:

> Space_AD wrote:
> And there is no additional criterium that limits records in the view?
> Could your problem be caused by NULL values? Just some 0.01 cents...
> robert
>
|||We found that this problem occured after some deadlock in the underlying
tables.
But not sure how dead locks affect the indexed view .
Cheers,
Space_AD
"arun.ns@.gmail.com" wrote:

> Yes, the indexed view is based on a single table.
>
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> CREATE VIEW <<view>> WITH SCHEMABINDING
> AS
> SELECT<<col1>>
> ,<<col2>>
> ,<<col3>>
> ,<<col4>>
> ,<<col5>>
> ,<<col6>>
> ,SUM(<<numeric col1>>)
> ,SUM(<<numeric col2>>)
> ,COUNT_BIG(*)
> FROM dbo.<<facttable>>AS pv
> WHEREBalance = 1
> GROUP
> BY <<col1>>
> ,<<col2>>
> ,<<col3>>
> ,<<col4>>
> ,<<col5>>
> ,<<col6>>
> GO
>
> SET
> ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL ,ARITHABORT,QUOTED_IDENTIFIER,ANSI_NULLS
> ON
> SET NUMERIC_ROUNDABORT OFF
> GO
> if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
> id = object_id(N'[dbo].[<<view>>]'))
> DROP INDEX [dbo].[<<view>>].[<<idxname>>]
> GO
> CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<view>>] (
> <<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>>)
> GO
> Thanks,
> Arun
>
|||we have found that this problem occured just after a deadlocking scenario
involving the underlying table.
But not sure why this deadlock is causing incorrect data in indexed view.
Cheers,
Space_AD
"Space_AD" wrote:
[vbcol=seagreen]
> The value column is not nullable.
> --
> Cheers,
> Space_AD
>
> "Robert Klemme" wrote:

Bug in indexed view?

We use SQL server 2000 sp3 database server in Windows 2000 Advanced server OS.
In production environment, one of the fact tables in our datamart has over
150 mil rows. A indexed view is built upon this fact table for reporting
purposes.
The problem is that when queried for the same criteria, the indexed view
returns different result than the underlying table. This problem has occured
twice in a single month. The problem was resolved upon rebuilding the indexed
view.
FYI. We have lots of data inserts as part of overnight batch process.
Queries:
--
SELECT sum(value)
FROM <<FactTableName>> (NOLOCK)
WHERE portfolioid = 100
and cob = '30 Jan 2006'
OPTION (EXPAND VIEWS)
SELECT sum(value)
FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
WHERE portfolioid = 100
and cob = '30 Jan 2006'
Any help on this is appreciated.
--
CheersHi
Does the view based on a single table?
"Space_AD" <SpaceAD@.discussions.microsoft.com> wrote in message
news:43DC2E60-C5E6-4B31-8B2F-893453A3C14C@.microsoft.com...
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced server
> OS.
> In production environment, one of the fact tables in our datamart has over
> 150 mil rows. A indexed view is built upon this fact table for reporting
> purposes.
> The problem is that when queried for the same criteria, the indexed view
> returns different result than the underlying table. This problem has
> occured
> twice in a single month. The problem was resolved upon rebuilding the
> indexed
> view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
> --
> Cheers
>|||Yes, the indexed view is based on a single table.
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE VIEW <<view>> WITH SCHEMABINDING
AS
SELECT <<col1>>
, <<col2>>
, <<col3>>
, <<col4>>
, <<col5>>
, <<col6>>
, SUM(<<numeric col1>>)
, SUM(<<numeric col2>>)
, COUNT_BIG(*)
FROM dbo.<<facttable>> AS pv
WHERE Balance = 1
GROUP
BY <<col1>>
, <<col2>>
, <<col3>>
, <<col4>>
, <<col5>>
, <<col6>>
GO
SET
ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL,ARITHABORT,QUOTED_IDENTIFIER,ANSI_NULLS
ON
SET NUMERIC_ROUNDABORT OFF
GO
if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
id = object_id(N'[dbo].[<<view>>]'))
DROP INDEX [dbo].[<<view>>].[<<idxname>>]
GO
CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<view>>] (
<<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>>)
GO
Thanks,
Arun|||Hi!
Try remove "nolock" hint from your queries.
Micle.
"Space_AD" <SpaceAD@.discussions.microsoft.com> wrote in message
news:43DC2E60-C5E6-4B31-8B2F-893453A3C14C@.microsoft.com...
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced server
> OS.
> In production environment, one of the fact tables in our datamart has over
> 150 mil rows. A indexed view is built upon this fact table for reporting
> purposes.
> The problem is that when queried for the same criteria, the indexed view
> returns different result than the underlying table. This problem has
> occured
> twice in a single month. The problem was resolved upon rebuilding the
> indexed
> view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
> --
> Cheers
>|||I have already tried it. It does not do any dirty reads..
FYI.. The bug has occured again today.
Cheers,
Arun|||CREATE CI on col1 and col2 ONLY
<arun.ns@.gmail.com> wrote in message
news:1138796568.572051.8640@.g49g2000cwa.googlegroups.com...
> Yes, the indexed view is based on a single table.
>
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_NULLS ON
> GO
> CREATE VIEW <<view>> WITH SCHEMABINDING
> AS
> SELECT <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> , SUM(<<numeric col1>>)
> , SUM(<<numeric col2>>)
> , COUNT_BIG(*)
> FROM dbo.<<facttable>> AS pv
> WHERE Balance = 1
> GROUP
> BY <<col1>>
> , <<col2>>
> , <<col3>>
> , <<col4>>
> , <<col5>>
> , <<col6>>
> GO
>
> SET
> ANSI_PADDING,ANSI_WARNINGS,CONCAT_NULL_YIELDS_NULL,ARITHABORT,QUOTED_IDENTIFIER,ANSI_NULLS
> ON
> SET NUMERIC_ROUNDABORT OFF
> GO
> if exists (select * from dbo.sysindexes where name = N'<<idxname>>' and
> id = object_id(N'[dbo].[<<view>>]'))
> DROP INDEX [dbo].[<<view>>].[<<idxname>>]
> GO
> CREATE UNIQUE CLUSTERED INDEX [<<idxname>>] ON [dbo].[<<view>>] (
> <<col1>>, <<col2>>, <<col3>>,<<col4>>, <<col5>>, <<col6>>)
> GO
> Thanks,
> Arun
>|||Space_AD wrote:
> We use SQL server 2000 sp3 database server in Windows 2000 Advanced
> server OS.
> In production environment, one of the fact tables in our datamart has
> over 150 mil rows. A indexed view is built upon this fact table for
> reporting purposes.
> The problem is that when queried for the same criteria, the indexed
> view returns different result than the underlying table. This problem
> has occured twice in a single month. The problem was resolved upon
> rebuilding the indexed view.
> FYI. We have lots of data inserts as part of overnight batch process.
> Queries:
> --
> SELECT sum(value)
> FROM <<FactTableName>> (NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> OPTION (EXPAND VIEWS)
> SELECT sum(value)
> FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> WHERE portfolioid = 100
> and cob = '30 Jan 2006'
> Any help on this is appreciated.
And there is no additional criterium that limits records in the view?
Could your problem be caused by NULL values? Just some 0.01 cents...
robert|||The value column is not nullable.
--
Cheers,
Space_AD
"Robert Klemme" wrote:
> Space_AD wrote:
> > We use SQL server 2000 sp3 database server in Windows 2000 Advanced
> > server OS.
> >
> > In production environment, one of the fact tables in our datamart has
> > over 150 mil rows. A indexed view is built upon this fact table for
> > reporting purposes.
> >
> > The problem is that when queried for the same criteria, the indexed
> > view returns different result than the underlying table. This problem
> > has occured twice in a single month. The problem was resolved upon
> > rebuilding the indexed view.
> >
> > FYI. We have lots of data inserts as part of overnight batch process.
> >
> > Queries:
> > --
> > SELECT sum(value)
> > FROM <<FactTableName>> (NOLOCK)
> > WHERE portfolioid = 100
> > and cob = '30 Jan 2006'
> > OPTION (EXPAND VIEWS)
> >
> > SELECT sum(value)
> > FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> > WHERE portfolioid = 100
> > and cob = '30 Jan 2006'
> >
> > Any help on this is appreciated.
> And there is no additional criterium that limits records in the view?
> Could your problem be caused by NULL values? Just some 0.01 cents...
> robert
>|||we have found that this problem occured just after a deadlocking scenario
involving the underlying table.
But not sure why this deadlock is causing incorrect data in indexed view.
--
Cheers,
Space_AD
"Space_AD" wrote:
> The value column is not nullable.
> --
> Cheers,
> Space_AD
>
> "Robert Klemme" wrote:
> > Space_AD wrote:
> > > We use SQL server 2000 sp3 database server in Windows 2000 Advanced
> > > server OS.
> > >
> > > In production environment, one of the fact tables in our datamart has
> > > over 150 mil rows. A indexed view is built upon this fact table for
> > > reporting purposes.
> > >
> > > The problem is that when queried for the same criteria, the indexed
> > > view returns different result than the underlying table. This problem
> > > has occured twice in a single month. The problem was resolved upon
> > > rebuilding the indexed view.
> > >
> > > FYI. We have lots of data inserts as part of overnight batch process.
> > >
> > > Queries:
> > > --
> > > SELECT sum(value)
> > > FROM <<FactTableName>> (NOLOCK)
> > > WHERE portfolioid = 100
> > > and cob = '30 Jan 2006'
> > > OPTION (EXPAND VIEWS)
> > >
> > > SELECT sum(value)
> > > FROM <<IndexedViewName>> (NOEXPAND, NOLOCK)
> > > WHERE portfolioid = 100
> > > and cob = '30 Jan 2006'
> > >
> > > Any help on this is appreciated.
> >
> > And there is no additional criterium that limits records in the view?
> > Could your problem be caused by NULL values? Just some 0.01 cents...
> >
> > robert
> >
> >

Wednesday, March 7, 2012

Bug in Copy database routine

I copied some databases from a SQL 2000 server to a SQL 2005 server. All the tables in the databases with auto incrementing identity columns (not for replication) had the identity information removed from the table definition. I used the SQL Management Object method.This is a known issue in SMO that is expected to be fixed in Server Pack 1.

Peter|||So what is the recommended way to copy databases from SQL 2000 to SQL 2005?

bug found in query

sql server 2000 versions 8.00.760 and 8.00.818
i found a strange bug. maybe it's not a bug, but it sure seems like one
to me. these tables are from a database for a cots product called
facility center.
the "bug" occurs down at the very bottom when you run the queries
specified. see my comments down there.
just to explain a little,
spbldinf_code is a building name
spbldrom_code is a room number
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spbldrom__spcharge]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[spcharge] DROP CONSTRAINT spbldrom__spcharge
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spbldrom__code]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[sprmutil] DROP CONSTRAINT spbldrom__code
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spbldrom]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[spbldrom]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[spcharge]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[spcharge]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sprmutil]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[sprmutil]
GO
CREATE TABLE [dbo].[spbldrom] (
[spbldinf_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[spbldrom_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[spfloors_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[splocation_code] [varchar] (72) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[spbldloc_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[saclass_code] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[saclstyp_code] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[description] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[phone] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[area] [decimal](12, 4) NULL ,
[notes] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[occ_vac] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[storageyn] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[location_code] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[subloc_type] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[user_name_created] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[date_created] [datetime] NULL ,
[user_name_modified] [varchar] (12) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[date_modified] [datetime] NULL ,
[group_owned_by] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[soft_delete_flag] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[spanlink_num] [int] NULL ,
[haz_mat] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[reservable_flag] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[spcharge] (
[sporg_code] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[spcharge_seq_num] [int] NOT NULL ,
[spbldinf_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[spfloors_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[spbldrom_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[area] [decimal](12, 4) NULL ,
[pct] [decimal](12, 4) NULL ,
[user_name_created] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[date_created] [datetime] NULL ,
[user_name_modified] [varchar] (12) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[date_modified] [datetime] NULL ,
[group_owned_by] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[soft_delete_flag] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[spanlink_num] [int] NULL ,
[owner_sporg_code] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[sprmutil] (
[spbldinf_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[spfloors_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[spbldrom_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[sprmutil_seq_num] [int] NOT NULL ,
[sporg_code] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[spprgrm_code] [varchar] (24) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[spromuse_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[pct] [numeric](12, 4) NULL ,
[area] [numeric](12, 4) NULL ,
[user_name_created] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[spromsub_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[date_created] [datetime] NULL ,
[user_name_modified] [varchar] (12) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[date_modified] [datetime] NULL ,
[group_owned_by] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[soft_delete_flag] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[spanlink_num] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[spbldrom] ADD
CONSTRAINT [DF__spbldrom__area__6FE99F9F] DEFAULT (0) FOR [area],
CONSTRAINT [DF__spbldrom__reserv__18427513] DEFAULT (0) FOR
[reservable_flag],
CONSTRAINT [xpkspbldrom] PRIMARY KEY NONCLUSTERED
(
[spbldinf_code],
[spbldrom_code]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF226spbldrom] ON [dbo].[spbldrom]([spbldinf_code],
[spbldloc_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF228spbldrom] ON [dbo].[spbldrom]([spbldinf_code])
WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF229spbldrom] ON [dbo].[spbldrom]([spbldinf_code],
[spfloors_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF433spbldrom] ON [dbo].[spbldrom]([saclass_code],
[saclstyp_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF877spbldrom] ON [dbo].[spbldrom]([splocation_code])
WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[spcharge] ADD
CONSTRAINT [DF__spcharge__area__2CBDA3B5] DEFAULT (0) FOR [area],
CONSTRAINT [DF__spcharge__pct__2DB1C7EE] DEFAULT (0) FOR [pct],
CONSTRAINT [xpkspcharge] PRIMARY KEY NONCLUSTERED
(
[sporg_code],
[spcharge_seq_num],
[spbldinf_code]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF236spcharge] ON [dbo].[spcharge]([sporg_code]) WITH
FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF274spcharge] ON [dbo].[spcharge]([spbldinf_code],
[spbldrom_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF275spcharge] ON [dbo].[spcharge]([spbldinf_code],
[spfloors_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF276spcharge] ON [dbo].[spcharge]([spbldinf_code])
WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[sprmutil] ADD
CONSTRAINT [XPKsprmutil] PRIMARY KEY NONCLUSTERED
(
[spbldinf_code],
[spfloors_code],
[spbldrom_code],
[sprmutil_seq_num]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF1040sprmutil] ON [dbo].[sprmutil]([sporg_code]) WITH
FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[spcharge] ADD
CONSTRAINT [spbldrom__spcharge] FOREIGN KEY
(
[spbldinf_code],
[spbldrom_code]
) REFERENCES [dbo].[spbldrom] (
[spbldinf_code],
[spbldrom_code]
)
GO
ALTER TABLE [dbo].[sprmutil] ADD
CONSTRAINT [spbldrom__code] FOREIGN KEY
(
[spbldinf_code],
[spbldrom_code]
) REFERENCES [dbo].[spbldrom] (
[spbldinf_code],
[spbldrom_code]
)
GO
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '1', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '2', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '3', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '4', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '5', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '6', '1')
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '1', 'org', 1)
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '2', 'org', 2)
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '3', 'org', 3)
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '4', 'org', 4)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '1', '1', 1)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '2', '1', 1)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '3', '1', 1)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '4', '1', 1)
go
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from sprmutil)
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from spcharge)
those two queries work properly. rooms 5 and 6 are returned because
they do not exist in the spcharge and/or sprmutil table.
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', NULL, 'org', 10)
set concat_null_yields_null off
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from sprmutil)
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from spcharge)
go
the two queries correctly return rooms 5 and 6.
set concat_null_yields_null on
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from sprmutil)
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from spcharge)
go
now the query for spcharge returns nothing. the one row with a null
value in the spcharge.spbldrom_code has prevented the query from
returning anything when it should still return rooms 5 and 6. i realize
that the concat_null_yields_null value is different, but imho it should
still return rooms 5 and 6.
if you run
set concat_null_yields_null on
select spbldinf_code + spbldrom_code from spcharge
set concat_null_yields_null off
select spbldinf_code + spbldrom_code from spcharge
you get record sets returned for both queries. the null value returned
in the top one apparently makes the not in clause in the previous
queries fail to work properly.
is there any way to report this to microsoft without paying for a
support call?> select spbldinf_code, spbldrom_code from spbldrom
> where spbldinf_code + spbldrom_code not in
> (select spbldinf_code + spbldrom_code from spcharge)
> go
> now the query for spcharge returns nothing. the one row with a null
> value in the spcharge.spbldrom_code has prevented the query from
> returning anything when it should still return rooms 5 and 6.
This isn't a bug it's standard SQL behaviour.
Because the subquery
(select spbldinf_code + spbldrom_code from spcharge)
includes a NULL, the predicate NOT IN returns UNKNOWN for every row in the
outer query, therefore nothing is returned. This is logical enough - if a
value in the set is UNKNOWN then you can't know whether any given value is
NOT IN the set.
I think the result you are looking for is this:
SELECT spbldinf_code, spbldrom_code
FROM spbldrom
WHERE spbldinf_code + spbldrom_code
NOT IN
(SELECT spbldinf_code + spbldrom_code
FROM spcharge
WHERE spbldinf_code + spbldrom_code IS NOT NULL)
--
David Portas
SQL Server MVP
--|||David Portas wrote:
> This is logical enough - if a
> value in the set is UNKNOWN then you can't know whether any given value is
> NOT IN the set.
that doesn't make any sense.
set A = 1, 2, 3
set B = 1, 2, NULL
if i'm trying to find all in A that aren't in B, then since
A.3 <> B.1 and
A.3 <> B.2 and
A.3 <> B.NULL
A.3 is not in set B
makes much more sense than saying "i can't figure out whether or not 3 is in
set B" when it's perfectly clear that there is no 3 in set B.|||> A.3 <> B.1 and
> A.3 <> B.2 and
> A.3 <> B.NULL
Yes, that's the logic. But the result of that last comparison is UNKNOWN not
TRUE (anything compared to NULL is UNKNOWN). Therefore the result of the NOT
IN predicate is also UNKNOWN. This is a common "gotcha" in SQL.
--
David Portas
SQL Server MVP
--

bug found in query

sql server 2000 versions 8.00.760 and 8.00.818
i found a strange bug. maybe it's not a bug, but it sure seems like one
to me. these tables are from a database for a cots product called
facility center.
the "bug" occurs down at the very bottom when you run the queries
specified. see my comments down there.
just to explain a little,
spbldinf_code is a building name
spbldrom_code is a room number
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[spbldrom__spcharge]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[spcharge] DROP CONSTRAINT spbldrom__spcharge
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[spbldrom__code]') and OBJECTPROPERTY(id,
N'IsForeignKey') = 1)
ALTER TABLE [dbo].[sprmutil] DROP CONSTRAINT spbldrom__code
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[spbldrom]') and OBJECTPROPERTY(id, N'IsUserTable'
) =
1)
drop table [dbo].[spbldrom]
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[spcharge]') and OBJECTPROPERTY(id, N'IsUserTable'
) =
1)
drop table [dbo].[spcharge]
GO
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[sprmutil]') and OBJECTPROPERTY(id, N'IsUserTable'
) =
1)
drop table [dbo].[sprmutil]
GO
CREATE TABLE [dbo].[spbldrom] (
[spbldinf_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT
NULL ,
[spbldrom_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT
NULL ,
[spfloors_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT
NULL ,
[splocation_code] [varchar] (72) COLLATE SQL_Latin1_General_CP1_CI_A
S
NULL ,
[spbldloc_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL
,
[saclass_code] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL
,
[saclstyp_code] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[description] [varchar] (25) COLLATE SQL_Latin1_General_CP1_CI_AS NU
LL
,
[phone] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[area] [decimal](12, 4) NULL ,
[notes] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[occ_vac] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[storageyn] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
,
[location_code] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[subloc_type] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_AS NU
LL
,
[user_name_created] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI
_AS
NULL ,
[date_created] [datetime] NULL ,
[user_name_modified] [varchar] (12) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[date_modified] [datetime] NULL ,
[group_owned_by] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[soft_delete_flag] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_A
S
NULL ,
[spanlink_num] [int] NULL ,
[haz_mat] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[reservable_flag] [int] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[spcharge] (
[sporg_code] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_AS NOT
NULL ,
[spcharge_seq_num] [int] NOT NULL ,
[spbldinf_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT
NULL ,
[spfloors_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL
,
[spbldrom_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[area] [decimal](12, 4) NULL ,
[pct] [decimal](12, 4) NULL ,
[user_name_created] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI
_AS
NULL ,
[date_created] [datetime] NULL ,
[user_name_modified] [varchar] (12) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[date_modified] [datetime] NULL ,
[group_owned_by] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[soft_delete_flag] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_A
S
NULL ,
[spanlink_num] [int] NULL ,
[owner_sporg_code] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_
AS
NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[sprmutil] (
[spbldinf_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT
NULL ,
[spfloors_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS N
OT
NULL ,
[spbldrom_code] [varchar] (16) COLLATE SQL_Latin1_General_CP1_CI_AS
NOT
NULL ,
[sprmutil_seq_num] [int] NOT NULL ,
[sporg_code] [varchar] (18) COLLATE SQL_Latin1_General_CP1_CI_AS NUL
L ,
[spprgrm_code] [varchar] (24) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL
,
[spromuse_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL
,
[pct] [numeric](12, 4) NULL ,
[area] [numeric](12, 4) NULL ,
[user_name_created] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI
_AS
NULL ,
[spromsub_code] [varchar] (8) COLLATE SQL_Latin1_General_CP1_CI_AS N
ULL
,
[date_created] [datetime] NULL ,
[user_name_modified] [varchar] (12) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[date_modified] [datetime] NULL ,
[group_owned_by] [varchar] (12) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[soft_delete_flag] [varchar] (1) COLLATE SQL_Latin1_General_CP1_CI_A
S
NULL ,
[spanlink_num] [int] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[spbldrom] ADD
CONSTRAINT [DF__spbldrom__area__6FE99F9F] DEFAULT (0) FOR [area],
CONSTRAINT [DF__spbldrom__reserv__18427513] DEFAULT (0) FOR
[reservable_flag],
CONSTRAINT [xpkspbldrom] PRIMARY KEY NONCLUSTERED
(
[spbldinf_code],
[spbldrom_code]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF226spbldrom] ON [dbo].[spbldrom]([spbldinf
_code],
[spbldloc_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF228spbldrom] ON [dbo].[spbldrom]([spbldinf
_code])
WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF229spbldrom] ON [dbo].[spbldrom]([spbldinf
_code],
[spfloors_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF433spbldrom] ON [dbo].[spbldrom]([saclass_
code],
[saclstyp_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF877spbldrom] ON [dbo].[spbldrom]([splocati
on_code])
WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[spcharge] ADD
CONSTRAINT [DF__spcharge__area__2CBDA3B5] DEFAULT (0) FOR [area],
CONSTRAINT [DF__spcharge__pct__2DB1C7EE] DEFAULT (0) FOR [pct],
CONSTRAINT [xpkspcharge] PRIMARY KEY NONCLUSTERED
(
[sporg_code],
[spcharge_seq_num],
[spbldinf_code]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF236spcharge] ON [dbo].[spcharge]([sporg_co
de]) WITH
FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF274spcharge] ON [dbo].[spcharge]([spbldinf
_code],
[spbldrom_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF275spcharge] ON [dbo].[spcharge]([spbldinf
_code],
[spfloors_code]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF276spcharge] ON [dbo].[spcharge]([spbldinf
_code])
WITH FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[sprmutil] ADD
CONSTRAINT [XPKsprmutil] PRIMARY KEY NONCLUSTERED
(
[spbldinf_code],
[spfloors_code],
[spbldrom_code],
[sprmutil_seq_num]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [XIF1040sprmutil] ON [dbo].[sprmutil]([sporg_c
ode]) WITH
FILLFACTOR = 90 ON [PRIMARY]
GO
ALTER TABLE [dbo].[spcharge] ADD
CONSTRAINT [spbldrom__spcharge] FOREIGN KEY
(
[spbldinf_code],
[spbldrom_code]
) REFERENCES [dbo].[spbldrom] (
[spbldinf_code],
[spbldrom_code]
)
GO
ALTER TABLE [dbo].[sprmutil] ADD
CONSTRAINT [spbldrom__code] FOREIGN KEY
(
[spbldinf_code],
[spbldrom_code]
) REFERENCES [dbo].[spbldrom] (
[spbldinf_code],
[spbldrom_code]
)
GO
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '1', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '2', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '3', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '4', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '5', '1')
insert into spbldrom (spbldinf_code, spbldrom_code, spfloors_code)
values ('1', '6', '1')
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '1', 'org', 1)
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '2', 'org', 2)
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '3', 'org', 3)
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', '4', 'org', 4)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '1', '1', 1)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '2', '1', 1)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '3', '1', 1)
insert into sprmutil (spbldinf_code, spbldrom_code, spfloors_code,
sprmutil_seq_num) values ('1', '4', '1', 1)
go
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from sprmutil)
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from spcharge)
those two queries work properly. rooms 5 and 6 are returned because
they do not exist in the spcharge and/or sprmutil table.
insert into spcharge (spbldinf_code, spbldrom_code, sporg_code,
spcharge_seq_num) values ('1', NULL, 'org', 10)
set concat_null_yields_null off
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from sprmutil)
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from spcharge)
go
the two queries correctly return rooms 5 and 6.
set concat_null_yields_null on
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from sprmutil)
select spbldinf_code, spbldrom_code from spbldrom
where spbldinf_code + spbldrom_code not in
(select spbldinf_code + spbldrom_code from spcharge)
go
now the query for spcharge returns nothing. the one row with a null
value in the spcharge.spbldrom_code has prevented the query from
returning anything when it should still return rooms 5 and 6. i realize
that the concat_null_yields_null value is different, but imho it should
still return rooms 5 and 6.
if you run
set concat_null_yields_null on
select spbldinf_code + spbldrom_code from spcharge
set concat_null_yields_null off
select spbldinf_code + spbldrom_code from spcharge
you get record sets returned for both queries. the null value returned
in the top one apparently makes the not in clause in the previous
queries fail to work properly.
is there any way to report this to microsoft without paying for a
support call?> select spbldinf_code, spbldrom_code from spbldrom
> where spbldinf_code + spbldrom_code not in
> (select spbldinf_code + spbldrom_code from spcharge)
> go
> now the query for spcharge returns nothing. the one row with a null
> value in the spcharge.spbldrom_code has prevented the query from
> returning anything when it should still return rooms 5 and 6.
This isn't a bug it's standard SQL behaviour.
Because the subquery
(select spbldinf_code + spbldrom_code from spcharge)
includes a NULL, the predicate NOT IN returns UNKNOWN for every row in the
outer query, therefore nothing is returned. This is logical enough - if a
value in the set is UNKNOWN then you can't know whether any given value is
NOT IN the set.
I think the result you are looking for is this:
SELECT spbldinf_code, spbldrom_code
FROM spbldrom
WHERE spbldinf_code + spbldrom_code
NOT IN
(SELECT spbldinf_code + spbldrom_code
FROM spcharge
WHERE spbldinf_code + spbldrom_code IS NOT NULL)
David Portas
SQL Server MVP
--|||David Portas wrote:

> This is logical enough - if a
> value in the set is UNKNOWN then you can't know whether any given value is
> NOT IN the set.
that doesn't make any sense.
set A = 1, 2, 3
set B = 1, 2, NULL
if i'm trying to find all in A that aren't in B, then since
A.3 <> B.1 and
A.3 <> B.2 and
A.3 <> B.NULL
A.3 is not in set B
makes much more sense than saying "i can't figure out whether or not 3 is in
set B" when it's perfectly clear that there is no 3 in set B.|||> A.3 <> B.1 and
> A.3 <> B.2 and
> A.3 <> B.NULL
Yes, that's the logic. But the result of that last comparison is UNKNOWN not
TRUE (anything compared to NULL is UNKNOWN). Therefore the result of the NOT
IN predicate is also UNKNOWN. This is a common "gotcha" in SQL.
David Portas
SQL Server MVP
--