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

Friday, March 30, 2012

Named Query on tables in separate dbs?

Is it possible to write a named query on tables in different databases?Sure, just use your standard TSQL syntax..

Select
A.field1,B.field2
from DB1.user.tablename A inner join DB2.user.tablename B
on A.ID = B.ID

C|||Actually I do not want to hard code the database name in the query. Can I use the datasources somehow?|||I have not been able to query across datasources.

If you just want to query one db, then you could create a view in one db that queries both dbs.

Named query not appearing in report builder

I'm having a heck of a time with named queries. At this point I just want a proof of concept in my DSV. I have a bunch of tables added to the DSV, and I would like to add a named query to it so the user can pick from the name query in report builder. What has to be done to make it appear in the report builder?

Nevermind. I didn't realize that the report model definition had to be refreshed.

Named pipes vs TCP/IP and NETWORKIO wait type

I am experiencing a problem whereby a 3rd party application is performing data transfers between tables in a database and they are taking enormous amounts of time.
I have no way of knowing what it is actually doing but when I examine the current activity, the RUNNABLE process shows NETWORKIO in the Wait Type column. What is this as I have not been able to find anything in BOL.
Related to this, what is the faster way of connection: named pipes or TCP/IP ? Both the client and the server have both enabled but the application is using TCP/IP to connect. Would named pipes be faster ?
Regards,
Peter Apostolakopoulos.
Check this out: http://sqldev.net/misc/WaitTypes.htm
Are both these tables in the same DB? What command is it using?
Andrew J. Kelly SQL MVP
"Peter Apostolakopoulos" <apostolp@.britannic.co.uk> wrote in message
news:BDFFD198-0B85-44EE-9CC3-55863CD7F980@.microsoft.com...
> I am experiencing a problem whereby a 3rd party application is performing
data transfers between tables in a database and they are taking enormous
amounts of time.
> I have no way of knowing what it is actually doing but when I examine the
current activity, the RUNNABLE process shows NETWORKIO in the Wait Type
column. What is this as I have not been able to find anything in BOL.
> Related to this, what is the faster way of connection: named pipes or
TCP/IP ? Both the client and the server have both enabled but the
application is using TCP/IP to connect. Would named pipes be faster ?
> Regards,
> Peter Apostolakopoulos.
|||Andrew,
Many thanks for the info. It is very useful. I am still having problems but I am pursuing this with the suppliers as I they have written some custom SQL to do the data migration which is "not the best" !!
Peter Apostolakopoulos
sql

Named pipes vs TCP/IP and NETWORKIO wait type

I am experiencing a problem whereby a 3rd party application is performing da
ta transfers between tables in a database and they are taking enormous amoun
ts of time.
I have no way of knowing what it is actually doing but when I examine the cu
rrent activity, the RUNNABLE process shows NETWORKIO in the Wait Type column
. What is this as I have not been able to find anything in BOL.
Related to this, what is the faster way of connection: named pipes or TCP/IP
? Both the client and the server have both enabled but the application is u
sing TCP/IP to connect. Would named pipes be faster ?
Regards,
Peter Apostolakopoulos.Check this out: http://sqldev.net/misc/WaitTypes.htm
Are both these tables in the same DB? What command is it using?
Andrew J. Kelly SQL MVP
"Peter Apostolakopoulos" <apostolp@.britannic.co.uk> wrote in message
news:BDFFD198-0B85-44EE-9CC3-55863CD7F980@.microsoft.com...
> I am experiencing a problem whereby a 3rd party application is performing
data transfers between tables in a database and they are taking enormous
amounts of time.
> I have no way of knowing what it is actually doing but when I examine the
current activity, the RUNNABLE process shows NETWORKIO in the Wait Type
column. What is this as I have not been able to find anything in BOL.
> Related to this, what is the faster way of connection: named pipes or
TCP/IP ? Both the client and the server have both enabled but the
application is using TCP/IP to connect. Would named pipes be faster ?
> Regards,
> Peter Apostolakopoulos.|||Andrew,
Many thanks for the info. It is very useful. I am still having problems but
I am pursuing this with the suppliers as I they have written some custom SQL
to do the data migration which is "not the best" !!
Peter Apostolakopoulos

Friday, March 23, 2012

Name of Tables and Columns

Hi,
i just migrated an database from oracle to sql server 2005 with the migration tool from microsoft (v3). the migration tool works only with uppercase table and column names, but i need them in lower case. is there a way to modify the names of tables and columns with t-sql to lower case?
Thx
Frank
There is no "alter table ... rename " command.
I have done in following way :
1.In Management Studio select all the tables->right click->Script table as->create to->New query editor window
(all this after I eliminated some scripting setting in Tool->Options->Scripting)
2.Copy all the script
3. Paste in Word ->Format->Change case->lower case : and all the words are lower case-> select all and copy
4.Back in theStudio->paste in a new query window-> select a test db
5. Run that script
(6.Then Import Export wizard etc )|||

yes u can do this using sp_rename system stored procedure . read more in BOL

Madhu

|||

As Madhu indicated, use sp_rename.

EXECUTE sp_rename 'tablename', 'TableName', object

|||Thank you all for help, 'sp_rename' works fine.

Wednesday, March 21, 2012

Naive Question on Export Data

Hi All,
When data is exported, to another database, the primary keys are not
available in the exported tables. Is there a way to export the data in the
tables along with all the properties of the table, I mean creating a ditto
copy of the original table along with data.
Thanks
kd
If you want a replica of the database, I suggest you use backup and restore.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"kd" <kd@.discussions.microsoft.com> wrote in message
news:948F9BFC-7F18-4BFA-9572-F516066E539F@.microsoft.com...
> Hi All,
> When data is exported, to another database, the primary keys are not
> available in the exported tables. Is there a way to export the data in the
> tables along with all the properties of the table, I mean creating a ditto
> copy of the original table along with data.
> Thanks
> kd
>

n00b: best way to import flat file with BIDS

Hi all,

I'm totally new to SQL Server 2k5 and need to do something rather basic: import some CSV files into tables. I'm getting translation errors and would like to know what's the best way to cast the strings before inserts.

I'm doing the import in BI Development Studio.

Current situation:

Created connection managers to csv files
created SQL server destinations pointing to the tables
connected them directly with a dataflow path
Ran the packadge: one import went just fine, the other one complains about conversion errors like "Conversion DT_STR and DT_I4 not supported"

Both tables have the same kind of fields (varchar, float, datetime, int)

I looked at converting the data using a transformation but am somewhat confused of which one to use.

What's the best way to transform the data before insert: derived column, import column or data conversion? Or something else I overlooked?

TIA

PeterFor doing this kind of work, I prefer to use bcp.exe over SSIS/DTS. It's a simple command line utility.

Look for "bcp utility" in BOL.

Monday, March 19, 2012

Mystery Table Delete!

I'm hoping someone out there can help me solve a mystery!
29 tables in our live database were deleted the other day
and we've no real idea how this could have happened.
We have found an entry in Application Event Viewer that
happened at about the same time as the tables vanished,
but we don't really understand what it means:
EventID: 17055
Categorey: (6)
Description: 3041: BACKUP failed to complete the command
dump tran [Claims] with no_log
I understand that this is saying that the command failed,
but where did the command come from? The user on the
event was creating new tables and replacing stored
procedures in the database at the time, however, [Claims]
is the name of the whole database!
We have recovered from the disaster now but really do need
to understand what has happened here, how it happened, and
how we can ensure it never happens again in the future.
Thanks in advance for any help.
Regards
PaulaCheck your web server logs, if there is web application connected. Check
your security logs...
"Pegasus" <anonymous@.discussions.microsoft.com> wrote in message
news:212c301c45a9e$73c9e3c0$a301280a@.phx
.gbl...
> I'm hoping someone out there can help me solve a mystery!
> 29 tables in our live database were deleted the other day
> and we've no real idea how this could have happened.
> We have found an entry in Application Event Viewer that
> happened at about the same time as the tables vanished,
> but we don't really understand what it means:
> EventID: 17055
> Categorey: (6)
> Description: 3041: BACKUP failed to complete the command
> dump tran [Claims] with no_log
> I understand that this is saying that the command failed,
> but where did the command come from? The user on the
> event was creating new tables and replacing stored
> procedures in the database at the time, however, [Claims]
> is the name of the whole database!
> We have recovered from the disaster now but really do need
> to understand what has happened here, how it happened, and
> how we can ensure it never happens again in the future.
> Thanks in advance for any help.
> Regards
> Paula|||There is no web application connected (to my knowledge)
and nothing is showing in the security logs.
Using SQL Server 2000.
Has been suggested that using Enterprise Manager and the
DTS Import/Export Wizard to move objects could have caused
the tables to be dropped? Any value in this theory?

>--Original Message--
>Check your web server logs, if there is web application
connected. Check
>your security logs...
>"Pegasus" <anonymous@.discussions.microsoft.com> wrote in
message
> news:212c301c45a9e$73c9e3c0$a301280a@.phx
.gbl...
mystery![vbcol=seagreen]
day[vbcol=seagreen]
failed,[vbcol=seagreen]
[Claims][vbcol=seagreen]
need[vbcol=seagreen]
and[vbcol=seagreen]
>
>.
>|||Probably the best way to see might be to get the tool from Lumigent (
www.lumigent.com)...
Give them a call and see if the tool will help in your situation.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Pegasus" <anonymous@.discussions.microsoft.com> wrote in message
news:212c301c45a9e$73c9e3c0$a301280a@.phx
.gbl...
> I'm hoping someone out there can help me solve a mystery!
> 29 tables in our live database were deleted the other day
> and we've no real idea how this could have happened.
> We have found an entry in Application Event Viewer that
> happened at about the same time as the tables vanished,
> but we don't really understand what it means:
> EventID: 17055
> Categorey: (6)
> Description: 3041: BACKUP failed to complete the command
> dump tran [Claims] with no_log
> I understand that this is saying that the command failed,
> but where did the command come from? The user on the
> event was creating new tables and replacing stored
> procedures in the database at the time, however, [Claims]
> is the name of the whole database!
> We have recovered from the disaster now but really do need
> to understand what has happened here, how it happened, and
> how we can ensure it never happens again in the future.
> Thanks in advance for any help.
> Regards
> Paula|||Try a log tool like LogExplorer from www.lumigent.com or ApexSQL Log from
www.apexsql.com to trawl trough your transaction logs and see what happened.
Jacco Schalkwijk
SQL Server MVP
<anonymous@.discussions.microsoft.com> wrote in message
news:216db01c45aac$4cc30320$a401280a@.phx
.gbl...[vbcol=seagreen]
> There is no web application connected (to my knowledge)
> and nothing is showing in the security logs.
> Using SQL Server 2000.
> Has been suggested that using Enterprise Manager and the
> DTS Import/Export Wizard to move objects could have caused
> the tables to be dropped? Any value in this theory?
>
> connected. Check
> message
> mystery!
> day
> failed,
> [Claims]
> need
> and|||Hi,
There is only Copy objects option in DTS and this will just copy the objects
to destination.
What recovery model you are using for this database, If it is FULL or
Bulk_logged and if you have trasnaction logs you can use the Log explorer
tool to analyze the situation which caused the object drop.
www.lumigent.com
If you do not have the transaction log backup, it is very difficult to find
the cause for the object drop.
Thanks
Hari
MCDBA
<anonymous@.discussions.microsoft.com> wrote in message
news:216db01c45aac$4cc30320$a401280a@.phx
.gbl...[vbcol=seagreen]
> There is no web application connected (to my knowledge)
> and nothing is showing in the security logs.
> Using SQL Server 2000.
> Has been suggested that using Enterprise Manager and the
> DTS Import/Export Wizard to move objects could have caused
> the tables to be dropped? Any value in this theory?
>
> connected. Check
> message
> mystery!
> day
> failed,
> [Claims]
> need
> and|||Thanks for your input.
No, we don't have the transaction log or a backup of it
(don't ask!!!) Is there another way to see what's
happened? There were 29 tables dropped in all so this
had very serious consequences and now we're trying to
ensure this doesn't happen again, but, without knowing
what DID happen we can't safeguard against it happening
again.

>--Original Message--
>Hi,
>There is only Copy objects option in DTS and this will
just copy the objects
>to destination.
>What recovery model you are using for this database, If
it is FULL or
>Bulk_logged and if you have trasnaction logs you can use
the Log explorer
>tool to analyze the situation which caused the object
drop.
>www.lumigent.com
>If you do not have the transaction log backup, it is very
difficult to find
>the cause for the object drop.
>--
>Thanks
>Hari
>MCDBA
><anonymous@.discussions.microsoft.com> wrote in message
> news:216db01c45aac$4cc30320$a401280a@.phx
.gbl...
caused[vbcol=seagreen]
in[vbcol=seagreen]
that[vbcol=seagreen]
vanished,[vbcol=seagreen]
command[vbcol=seagreen]
the[vbcol=seagreen]
happened,[vbcol=seagreen]
future.[vbcol=seagreen]
>
>.
>

Mystery Table Delete!

I'm hoping someone out there can help me solve a mystery!
29 tables in our live database were deleted the other day
and we've no real idea how this could have happened.
We have found an entry in Application Event Viewer that
happened at about the same time as the tables vanished,
but we don't really understand what it means:
EventID: 17055
Categorey: (6)
Description: 3041: BACKUP failed to complete the command
dump tran [Claims] with no_log
I understand that this is saying that the command failed,
but where did the command come from? The user on the
event was creating new tables and replacing stored
procedures in the database at the time, however, [Claims]
is the name of the whole database!
We have recovered from the disaster now but really do need
to understand what has happened here, how it happened, and
how we can ensure it never happens again in the future.
Thanks in advance for any help.
Regards
PaulaCheck your web server logs, if there is web application connected. Check
your security logs...
"Pegasus" <anonymous@.discussions.microsoft.com> wrote in message
news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
> I'm hoping someone out there can help me solve a mystery!
> 29 tables in our live database were deleted the other day
> and we've no real idea how this could have happened.
> We have found an entry in Application Event Viewer that
> happened at about the same time as the tables vanished,
> but we don't really understand what it means:
> EventID: 17055
> Categorey: (6)
> Description: 3041: BACKUP failed to complete the command
> dump tran [Claims] with no_log
> I understand that this is saying that the command failed,
> but where did the command come from? The user on the
> event was creating new tables and replacing stored
> procedures in the database at the time, however, [Claims]
> is the name of the whole database!
> We have recovered from the disaster now but really do need
> to understand what has happened here, how it happened, and
> how we can ensure it never happens again in the future.
> Thanks in advance for any help.
> Regards
> Paula|||There is no web application connected (to my knowledge)
and nothing is showing in the security logs.
Using SQL Server 2000.
Has been suggested that using Enterprise Manager and the
DTS Import/Export Wizard to move objects could have caused
the tables to be dropped? Any value in this theory?
>--Original Message--
>Check your web server logs, if there is web application
connected. Check
>your security logs...
>"Pegasus" <anonymous@.discussions.microsoft.com> wrote in
message
>news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
>> I'm hoping someone out there can help me solve a
mystery!
>> 29 tables in our live database were deleted the other
day
>> and we've no real idea how this could have happened.
>> We have found an entry in Application Event Viewer that
>> happened at about the same time as the tables vanished,
>> but we don't really understand what it means:
>> EventID: 17055
>> Categorey: (6)
>> Description: 3041: BACKUP failed to complete the command
>> dump tran [Claims] with no_log
>> I understand that this is saying that the command
failed,
>> but where did the command come from? The user on the
>> event was creating new tables and replacing stored
>> procedures in the database at the time, however,
[Claims]
>> is the name of the whole database!
>> We have recovered from the disaster now but really do
need
>> to understand what has happened here, how it happened,
and
>> how we can ensure it never happens again in the future.
>> Thanks in advance for any help.
>> Regards
>> Paula
>
>.
>|||Probably the best way to see might be to get the tool from Lumigent (
www.lumigent.com)...
Give them a call and see if the tool will help in your situation.
--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Pegasus" <anonymous@.discussions.microsoft.com> wrote in message
news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
> I'm hoping someone out there can help me solve a mystery!
> 29 tables in our live database were deleted the other day
> and we've no real idea how this could have happened.
> We have found an entry in Application Event Viewer that
> happened at about the same time as the tables vanished,
> but we don't really understand what it means:
> EventID: 17055
> Categorey: (6)
> Description: 3041: BACKUP failed to complete the command
> dump tran [Claims] with no_log
> I understand that this is saying that the command failed,
> but where did the command come from? The user on the
> event was creating new tables and replacing stored
> procedures in the database at the time, however, [Claims]
> is the name of the whole database!
> We have recovered from the disaster now but really do need
> to understand what has happened here, how it happened, and
> how we can ensure it never happens again in the future.
> Thanks in advance for any help.
> Regards
> Paula|||Try a log tool like LogExplorer from www.lumigent.com or ApexSQL Log from
www.apexsql.com to trawl trough your transaction logs and see what happened.
--
Jacco Schalkwijk
SQL Server MVP
<anonymous@.discussions.microsoft.com> wrote in message
news:216db01c45aac$4cc30320$a401280a@.phx.gbl...
> There is no web application connected (to my knowledge)
> and nothing is showing in the security logs.
> Using SQL Server 2000.
> Has been suggested that using Enterprise Manager and the
> DTS Import/Export Wizard to move objects could have caused
> the tables to be dropped? Any value in this theory?
>
> >--Original Message--
> >Check your web server logs, if there is web application
> connected. Check
> >your security logs...
> >
> >"Pegasus" <anonymous@.discussions.microsoft.com> wrote in
> message
> >news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
> >> I'm hoping someone out there can help me solve a
> mystery!
> >>
> >> 29 tables in our live database were deleted the other
> day
> >> and we've no real idea how this could have happened.
> >>
> >> We have found an entry in Application Event Viewer that
> >> happened at about the same time as the tables vanished,
> >> but we don't really understand what it means:
> >> EventID: 17055
> >> Categorey: (6)
> >> Description: 3041: BACKUP failed to complete the command
> >> dump tran [Claims] with no_log
> >>
> >> I understand that this is saying that the command
> failed,
> >> but where did the command come from? The user on the
> >> event was creating new tables and replacing stored
> >> procedures in the database at the time, however,
> [Claims]
> >> is the name of the whole database!
> >>
> >> We have recovered from the disaster now but really do
> need
> >> to understand what has happened here, how it happened,
> and
> >> how we can ensure it never happens again in the future.
> >>
> >> Thanks in advance for any help.
> >>
> >> Regards
> >>
> >> Paula
> >
> >
> >.
> >|||Hi,
There is only Copy objects option in DTS and this will just copy the objects
to destination.
What recovery model you are using for this database, If it is FULL or
Bulk_logged and if you have trasnaction logs you can use the Log explorer
tool to analyze the situation which caused the object drop.
www.lumigent.com
If you do not have the transaction log backup, it is very difficult to find
the cause for the object drop.
--
Thanks
Hari
MCDBA
<anonymous@.discussions.microsoft.com> wrote in message
news:216db01c45aac$4cc30320$a401280a@.phx.gbl...
> There is no web application connected (to my knowledge)
> and nothing is showing in the security logs.
> Using SQL Server 2000.
> Has been suggested that using Enterprise Manager and the
> DTS Import/Export Wizard to move objects could have caused
> the tables to be dropped? Any value in this theory?
>
> >--Original Message--
> >Check your web server logs, if there is web application
> connected. Check
> >your security logs...
> >
> >"Pegasus" <anonymous@.discussions.microsoft.com> wrote in
> message
> >news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
> >> I'm hoping someone out there can help me solve a
> mystery!
> >>
> >> 29 tables in our live database were deleted the other
> day
> >> and we've no real idea how this could have happened.
> >>
> >> We have found an entry in Application Event Viewer that
> >> happened at about the same time as the tables vanished,
> >> but we don't really understand what it means:
> >> EventID: 17055
> >> Categorey: (6)
> >> Description: 3041: BACKUP failed to complete the command
> >> dump tran [Claims] with no_log
> >>
> >> I understand that this is saying that the command
> failed,
> >> but where did the command come from? The user on the
> >> event was creating new tables and replacing stored
> >> procedures in the database at the time, however,
> [Claims]
> >> is the name of the whole database!
> >>
> >> We have recovered from the disaster now but really do
> need
> >> to understand what has happened here, how it happened,
> and
> >> how we can ensure it never happens again in the future.
> >>
> >> Thanks in advance for any help.
> >>
> >> Regards
> >>
> >> Paula
> >
> >
> >.
> >|||Thanks for your input. I have already got information
about LogExplorer from www.lumigent.com and we're looking
into purchasing this product for use in the future.
Unfortunately the log file no longer exists (don't ask!!!)
so this software would be of no use on this occasion. Is
there any other way forward on this?
Could the DTS Import/Export Wizard have caused this much
destruction by copying over 2 new tables and 3 existing
stored procedures from a development copy of the
database? The user insists that the objects were not
transferred to the live database using this Wizard. Even
if "dependant objects" was selected, could there be a
scenario where SQL would have dropped all tables
referenced in the SP's and all tables related to those
tables? If this is possible, can we disable the use of
DTS Import/Export wizard in Enterprise Manager for ALL
users?
>--Original Message--
>I'm hoping someone out there can help me solve a mystery!
>29 tables in our live database were deleted the other day
>and we've no real idea how this could have happened.
>We have found an entry in Application Event Viewer that
>happened at about the same time as the tables vanished,
>but we don't really understand what it means:
>EventID: 17055
>Categorey: (6)
>Description: 3041: BACKUP failed to complete the command
>dump tran [Claims] with no_log
>I understand that this is saying that the command failed,
>but where did the command come from? The user on the
>event was creating new tables and replacing stored
>procedures in the database at the time, however, [Claims]
>is the name of the whole database!
>We have recovered from the disaster now but really do
need
>to understand what has happened here, how it happened,
and
>how we can ensure it never happens again in the future.
>Thanks in advance for any help.
>Regards
>Paula
>.
>|||Thanks for your input.
No, we don't have the transaction log or a backup of it
(don't ask!!!) Is there another way to see what's
happened? There were 29 tables dropped in all so this
had very serious consequences and now we're trying to
ensure this doesn't happen again, but, without knowing
what DID happen we can't safeguard against it happening
again.
>--Original Message--
>Hi,
>There is only Copy objects option in DTS and this will
just copy the objects
>to destination.
>What recovery model you are using for this database, If
it is FULL or
>Bulk_logged and if you have trasnaction logs you can use
the Log explorer
>tool to analyze the situation which caused the object
drop.
>www.lumigent.com
>If you do not have the transaction log backup, it is very
difficult to find
>the cause for the object drop.
>--
>Thanks
>Hari
>MCDBA
><anonymous@.discussions.microsoft.com> wrote in message
>news:216db01c45aac$4cc30320$a401280a@.phx.gbl...
>> There is no web application connected (to my knowledge)
>> and nothing is showing in the security logs.
>> Using SQL Server 2000.
>> Has been suggested that using Enterprise Manager and the
>> DTS Import/Export Wizard to move objects could have
caused
>> the tables to be dropped? Any value in this theory?
>>
>> >--Original Message--
>> >Check your web server logs, if there is web application
>> connected. Check
>> >your security logs...
>> >
>> >"Pegasus" <anonymous@.discussions.microsoft.com> wrote
in
>> message
>> >news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
>> >> I'm hoping someone out there can help me solve a
>> mystery!
>> >>
>> >> 29 tables in our live database were deleted the other
>> day
>> >> and we've no real idea how this could have happened.
>> >>
>> >> We have found an entry in Application Event Viewer
that
>> >> happened at about the same time as the tables
vanished,
>> >> but we don't really understand what it means:
>> >> EventID: 17055
>> >> Categorey: (6)
>> >> Description: 3041: BACKUP failed to complete the
command
>> >> dump tran [Claims] with no_log
>> >>
>> >> I understand that this is saying that the command
>> failed,
>> >> but where did the command come from? The user on
the
>> >> event was creating new tables and replacing stored
>> >> procedures in the database at the time, however,
>> [Claims]
>> >> is the name of the whole database!
>> >>
>> >> We have recovered from the disaster now but really do
>> need
>> >> to understand what has happened here, how it
happened,
>> and
>> >> how we can ensure it never happens again in the
future.
>> >>
>> >> Thanks in advance for any help.
>> >>
>> >> Regards
>> >>
>> >> Paula
>> >
>> >
>> >.
>> >
>
>.
>

Mystery Table Delete!

I'm hoping someone out there can help me solve a mystery!
29 tables in our live database were deleted the other day
and we've no real idea how this could have happened.
We have found an entry in Application Event Viewer that
happened at about the same time as the tables vanished,
but we don't really understand what it means:
EventID: 17055
Categorey: (6)
Description: 3041: BACKUP failed to complete the command
dump tran [Claims] with no_log
I understand that this is saying that the command failed,
but where did the command come from? The user on the
event was creating new tables and replacing stored
procedures in the database at the time, however, [Claims]
is the name of the whole database!
We have recovered from the disaster now but really do need
to understand what has happened here, how it happened, and
how we can ensure it never happens again in the future.
Thanks in advance for any help.
Regards
Paula
Check your web server logs, if there is web application connected. Check
your security logs...
"Pegasus" <anonymous@.discussions.microsoft.com> wrote in message
news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
> I'm hoping someone out there can help me solve a mystery!
> 29 tables in our live database were deleted the other day
> and we've no real idea how this could have happened.
> We have found an entry in Application Event Viewer that
> happened at about the same time as the tables vanished,
> but we don't really understand what it means:
> EventID: 17055
> Categorey: (6)
> Description: 3041: BACKUP failed to complete the command
> dump tran [Claims] with no_log
> I understand that this is saying that the command failed,
> but where did the command come from? The user on the
> event was creating new tables and replacing stored
> procedures in the database at the time, however, [Claims]
> is the name of the whole database!
> We have recovered from the disaster now but really do need
> to understand what has happened here, how it happened, and
> how we can ensure it never happens again in the future.
> Thanks in advance for any help.
> Regards
> Paula
|||There is no web application connected (to my knowledge)
and nothing is showing in the security logs.
Using SQL Server 2000.
Has been suggested that using Enterprise Manager and the
DTS Import/Export Wizard to move objects could have caused
the tables to be dropped? Any value in this theory?

>--Original Message--
>Check your web server logs, if there is web application
connected. Check
>your security logs...
>"Pegasus" <anonymous@.discussions.microsoft.com> wrote in
message[vbcol=seagreen]
>news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
mystery![vbcol=seagreen]
day[vbcol=seagreen]
failed,[vbcol=seagreen]
[Claims][vbcol=seagreen]
need[vbcol=seagreen]
and
>
>.
>
|||Probably the best way to see might be to get the tool from Lumigent (
www.lumigent.com)...
Give them a call and see if the tool will help in your situation.
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Pegasus" <anonymous@.discussions.microsoft.com> wrote in message
news:212c301c45a9e$73c9e3c0$a301280a@.phx.gbl...
> I'm hoping someone out there can help me solve a mystery!
> 29 tables in our live database were deleted the other day
> and we've no real idea how this could have happened.
> We have found an entry in Application Event Viewer that
> happened at about the same time as the tables vanished,
> but we don't really understand what it means:
> EventID: 17055
> Categorey: (6)
> Description: 3041: BACKUP failed to complete the command
> dump tran [Claims] with no_log
> I understand that this is saying that the command failed,
> but where did the command come from? The user on the
> event was creating new tables and replacing stored
> procedures in the database at the time, however, [Claims]
> is the name of the whole database!
> We have recovered from the disaster now but really do need
> to understand what has happened here, how it happened, and
> how we can ensure it never happens again in the future.
> Thanks in advance for any help.
> Regards
> Paula
|||Try a log tool like LogExplorer from www.lumigent.com or ApexSQL Log from
www.apexsql.com to trawl trough your transaction logs and see what happened.
Jacco Schalkwijk
SQL Server MVP
<anonymous@.discussions.microsoft.com> wrote in message
news:216db01c45aac$4cc30320$a401280a@.phx.gbl...[vbcol=seagreen]
> There is no web application connected (to my knowledge)
> and nothing is showing in the security logs.
> Using SQL Server 2000.
> Has been suggested that using Enterprise Manager and the
> DTS Import/Export Wizard to move objects could have caused
> the tables to be dropped? Any value in this theory?
>
> connected. Check
> message
> mystery!
> day
> failed,
> [Claims]
> need
> and
|||Hi,
There is only Copy objects option in DTS and this will just copy the objects
to destination.
What recovery model you are using for this database, If it is FULL or
Bulk_logged and if you have trasnaction logs you can use the Log explorer
tool to analyze the situation which caused the object drop.
www.lumigent.com
If you do not have the transaction log backup, it is very difficult to find
the cause for the object drop.
Thanks
Hari
MCDBA
<anonymous@.discussions.microsoft.com> wrote in message
news:216db01c45aac$4cc30320$a401280a@.phx.gbl...[vbcol=seagreen]
> There is no web application connected (to my knowledge)
> and nothing is showing in the security logs.
> Using SQL Server 2000.
> Has been suggested that using Enterprise Manager and the
> DTS Import/Export Wizard to move objects could have caused
> the tables to be dropped? Any value in this theory?
>
> connected. Check
> message
> mystery!
> day
> failed,
> [Claims]
> need
> and
|||Thanks for your input.
No, we don't have the transaction log or a backup of it
(don't ask!!!) Is there another way to see what's
happened? There were 29 tables dropped in all so this
had very serious consequences and now we're trying to
ensure this doesn't happen again, but, without knowing
what DID happen we can't safeguard against it happening
again.

>--Original Message--
>Hi,
>There is only Copy objects option in DTS and this will
just copy the objects
>to destination.
>What recovery model you are using for this database, If
it is FULL or
>Bulk_logged and if you have trasnaction logs you can use
the Log explorer
>tool to analyze the situation which caused the object
drop.
>www.lumigent.com
>If you do not have the transaction log backup, it is very
difficult to find[vbcol=seagreen]
>the cause for the object drop.
>--
>Thanks
>Hari
>MCDBA
><anonymous@.discussions.microsoft.com> wrote in message
>news:216db01c45aac$4cc30320$a401280a@.phx.gbl...
caused[vbcol=seagreen]
in[vbcol=seagreen]
that[vbcol=seagreen]
vanished,[vbcol=seagreen]
command[vbcol=seagreen]
the[vbcol=seagreen]
happened,[vbcol=seagreen]
future.
>
>.
>

Mysteriously changing datetime data

I know this may seem like a weird thing, but today something very strange
happened to one of my database tables. The table has three columns that are
of type datetime. They normally contain values such as 08/12/2004 16:03:35.
One of the three columns, however, now shows either 08/12/2004 only or
08/12/2004 00:00:00. The other two columns are still "normal".
No update queries have been run against this table.
Does anybody know why the dates would have changed like that?DATETIME columns don't contain any inherent format and they always include
both date and time. It looks like your client application, whatever that may
be, is formatting the date differently to what you expect. Check the
regional settings on your PC or any other options in your app that may
affect date formatting.
David Portas
SQL Server MVP
--|||Where are you looking, in Enterprise Manager? Try using SELECT cols FROM
table in Query Analyzer.
http://www.aspfaq.com/
(Reverse address to reply.)
"SackerMan" <SackerMan@.discussions.microsoft.com> wrote in message
news:6529C05A-2374-421C-93C4-6A498163F365@.microsoft.com...
> I know this may seem like a weird thing, but today something very strange
> happened to one of my database tables. The table has three columns that
are
> of type datetime. They normally contain values such as 08/12/2004
16:03:35.
> One of the three columns, however, now shows either 08/12/2004 only or
> 08/12/2004 00:00:00. The other two columns are still "normal".
> No update queries have been run against this table.
> Does anybody know why the dates would have changed like that?|||Hi SackerMan
The values actually stored in a datetime column don't 'look' anything like
what you have shown us. They are stored in an internal unambigous format
that you never see.
How a datetime value 'looks' depends on the tool and the command you use to
display it.
So, how are you actually seeing these values?
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"SackerMan" <SackerMan@.discussions.microsoft.com> wrote in message
news:6529C05A-2374-421C-93C4-6A498163F365@.microsoft.com...
> I know this may seem like a weird thing, but today something very strange
> happened to one of my database tables. The table has three columns that
are
> of type datetime. They normally contain values such as 08/12/2004
16:03:35.
> One of the three columns, however, now shows either 08/12/2004 only or
> 08/12/2004 00:00:00. The other two columns are still "normal".
> No update queries have been run against this table.
> Does anybody know why the dates would have changed like that?

Mysteriously changing datetime data

I know this may seem like a weird thing, but today something very strange
happened to one of my database tables. The table has three columns that are
of type datetime. They normally contain values such as 08/12/2004 16:03:35.
One of the three columns, however, now shows either 08/12/2004 only or
08/12/2004 00:00:00. The other two columns are still "normal".
No update queries have been run against this table.
Does anybody know why the dates would have changed like that?DATETIME columns don't contain any inherent format and they always include
both date and time. It looks like your client application, whatever that may
be, is formatting the date differently to what you expect. Check the
regional settings on your PC or any other options in your app that may
affect date formatting.
--
David Portas
SQL Server MVP
--|||Where are you looking, in Enterprise Manager? Try using SELECT cols FROM
table in Query Analyzer.
--
http://www.aspfaq.com/
(Reverse address to reply.)
"SackerMan" <SackerMan@.discussions.microsoft.com> wrote in message
news:6529C05A-2374-421C-93C4-6A498163F365@.microsoft.com...
> I know this may seem like a weird thing, but today something very strange
> happened to one of my database tables. The table has three columns that
are
> of type datetime. They normally contain values such as 08/12/2004
16:03:35.
> One of the three columns, however, now shows either 08/12/2004 only or
> 08/12/2004 00:00:00. The other two columns are still "normal".
> No update queries have been run against this table.
> Does anybody know why the dates would have changed like that?|||Hi SackerMan
The values actually stored in a datetime column don't 'look' anything like
what you have shown us. They are stored in an internal unambigous format
that you never see.
How a datetime value 'looks' depends on the tool and the command you use to
display it.
So, how are you actually seeing these values?
--
HTH
--
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"SackerMan" <SackerMan@.discussions.microsoft.com> wrote in message
news:6529C05A-2374-421C-93C4-6A498163F365@.microsoft.com...
> I know this may seem like a weird thing, but today something very strange
> happened to one of my database tables. The table has three columns that
are
> of type datetime. They normally contain values such as 08/12/2004
16:03:35.
> One of the three columns, however, now shows either 08/12/2004 only or
> 08/12/2004 00:00:00. The other two columns are still "normal".
> No update queries have been run against this table.
> Does anybody know why the dates would have changed like that?

Mysteriously changing datetime data

I know this may seem like a weird thing, but today something very strange
happened to one of my database tables. The table has three columns that are
of type datetime. They normally contain values such as 08/12/2004 16:03:35.
One of the three columns, however, now shows either 08/12/2004 only or
08/12/2004 00:00:00. The other two columns are still "normal".
No update queries have been run against this table.
Does anybody know why the dates would have changed like that?
DATETIME columns don't contain any inherent format and they always include
both date and time. It looks like your client application, whatever that may
be, is formatting the date differently to what you expect. Check the
regional settings on your PC or any other options in your app that may
affect date formatting.
David Portas
SQL Server MVP
|||Where are you looking, in Enterprise Manager? Try using SELECT cols FROM
table in Query Analyzer.
http://www.aspfaq.com/
(Reverse address to reply.)
"SackerMan" <SackerMan@.discussions.microsoft.com> wrote in message
news:6529C05A-2374-421C-93C4-6A498163F365@.microsoft.com...
> I know this may seem like a weird thing, but today something very strange
> happened to one of my database tables. The table has three columns that
are
> of type datetime. They normally contain values such as 08/12/2004
16:03:35.
> One of the three columns, however, now shows either 08/12/2004 only or
> 08/12/2004 00:00:00. The other two columns are still "normal".
> No update queries have been run against this table.
> Does anybody know why the dates would have changed like that?
|||Hi SackerMan
The values actually stored in a datetime column don't 'look' anything like
what you have shown us. They are stored in an internal unambigous format
that you never see.
How a datetime value 'looks' depends on the tool and the command you use to
display it.
So, how are you actually seeing these values?
HTH
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"SackerMan" <SackerMan@.discussions.microsoft.com> wrote in message
news:6529C05A-2374-421C-93C4-6A498163F365@.microsoft.com...
> I know this may seem like a weird thing, but today something very strange
> happened to one of my database tables. The table has three columns that
are
> of type datetime. They normally contain values such as 08/12/2004
16:03:35.
> One of the three columns, however, now shows either 08/12/2004 only or
> 08/12/2004 00:00:00. The other two columns are still "normal".
> No update queries have been run against this table.
> Does anybody know why the dates would have changed like that?

Mysterious SQL Server Dropping Tables

We had just setup MS SQL 2000 (SP3), running on Windows 2000 (SP4). Both SQL
and Windows2000 Server has been patched with all security updates as per
Microsoft websites.
On the server PC, it is also running Norton Antivirus Corporate Edition 7.6
with the latest AV definition. I've also lost count of how many times we
scan the server for virus but none were found.
This is a newly setup server but we're observing the tables in the SQL
server dropping out of no apparent reason. A check on the actual data
directory we found that the database .LDF is missing and the EM marks it as
'suspect'.
What kind of information should I provide in order to further trouble shoot
this problem?
Since this is a test server we're only running it on 2 x 80GB IDE harddisk
and as far as I can tell there is no bad sectors found. Has anyone encounter
anything of such? Please help. TQ.
--
Steven Ung
"The source of all greatness lies within you" - Anonymous> This is a newly setup server but we're observing the tables in the SQL
> server dropping out of no apparent reason. A check on the actual data
> directory we found that the database .LDF is missing and the EM marks it
> as
> 'suspect'.
The tables, or the log file? Sounds like both are happening. Once you get
the system back where it should be, you might want to use a program like
filemon (http://www.sysinternals.com/ntw2k/utilities.shtml) to see what
process is accessing the LDF file.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/|||"Aaron Bertrand [MVP]" <aaron@.TRASHaspfaq.com> wrote in message
news:ulucZdfHEHA.2876@.TK2MSFTNGP09.phx.gbl...
> The tables, or the log file? Sounds like both are happening.
Both, but the tables are the ones dropping/missing first.
Does drive caching has anything to do with it? The Windows Event Log
complaints that drive cache is disabled. I've temporary enable it and still
checking the results. But since no one has had this problem before, I'm not
certain of whether this is the solution or what is causing the tables to
drop or go missing.

> Once you get
> the system back where it should be, you might want to use a program like
> filemon (http://www.sysinternals.com/ntw2k/utilities.shtml) to see what
> process is accessing the LDF file.
I've downloaded the utility but could not find any process out of the
extraordinary.
Steven Ung
"The source of all greatness lies within you" - Anonymous

Mysterious SQL Server Dropping Tables

We had just setup MS SQL 2000 (SP3), running on Windows 2000 (SP4). Both SQL
and Windows2000 Server has been patched with all security updates as per
Microsoft websites.
On the server PC, it is also running Norton Antivirus Corporate Edition 7.6
with the latest AV definition. I've also lost count of how many times we
scan the server for virus but none were found.
This is a newly setup server but we're observing the tables in the SQL
server dropping out of no apparent reason. A check on the actual data
directory we found that the database .LDF is missing and the EM marks it as
'suspect'.
What kind of information should I provide in order to further trouble shoot
this problem?
Since this is a test server we're only running it on 2 x 80GB IDE harddisk
and as far as I can tell there is no bad sectors found. Has anyone encounter
anything of such? Please help. TQ.
--
Steven Ung
"The source of all greatness lies within you" - Anonymous> This is a newly setup server but we're observing the tables in the SQL
> server dropping out of no apparent reason. A check on the actual data
> directory we found that the database .LDF is missing and the EM marks it
> as
> 'suspect'.
The tables, or the log file? Sounds like both are happening. Once you get
the system back where it should be, you might want to use a program like
filemon (http://www.sysinternals.com/ntw2k/utilities.shtml) to see what
process is accessing the LDF file.
--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/|||"Aaron Bertrand [MVP]" <aaron@.TRASHaspfaq.com> wrote in message
news:ulucZdfHEHA.2876@.TK2MSFTNGP09.phx.gbl...
> > This is a newly setup server but we're observing the tables in the SQL
> > server dropping out of no apparent reason. A check on the actual data
> > directory we found that the database .LDF is missing and the EM marks it
> > as
> > 'suspect'.
> The tables, or the log file? Sounds like both are happening.
Both, but the tables are the ones dropping/missing first.
Does drive caching has anything to do with it? The Windows Event Log
complaints that drive cache is disabled. I've temporary enable it and still
checking the results. But since no one has had this problem before, I'm not
certain of whether this is the solution or what is causing the tables to
drop or go missing.
> Once you get
> the system back where it should be, you might want to use a program like
> filemon (http://www.sysinternals.com/ntw2k/utilities.shtml) to see what
> process is accessing the LDF file.
I've downloaded the utility but could not find any process out of the
extraordinary.
--
Steven Ung
"The source of all greatness lies within you" - Anonymous

Mysterious SQL Server Dropping Tables

We had just setup MS SQL 2000 (SP3), running on Windows 2000 (SP4). Both SQL
and Windows2000 Server has been patched with all security updates as per
Microsoft websites.
On the server PC, it is also running Norton Antivirus Corporate Edition 7.6
with the latest AV definition. I've also lost count of how many times we
scan the server for virus but none were found.
This is a newly setup server but we're observing the tables in the SQL
server dropping out of no apparent reason. A check on the actual data
directory we found that the database .LDF is missing and the EM marks it as
'suspect'.
What kind of information should I provide in order to further trouble shoot
this problem?
Since this is a test server we're only running it on 2 x 80GB IDE harddisk
and as far as I can tell there is no bad sectors found. Has anyone encounter
anything of such? Please help. TQ.
Steven Ung
"The source of all greatness lies within you" - Anonymous
> This is a newly setup server but we're observing the tables in the SQL
> server dropping out of no apparent reason. A check on the actual data
> directory we found that the database .LDF is missing and the EM marks it
> as
> 'suspect'.
The tables, or the log file? Sounds like both are happening. Once you get
the system back where it should be, you might want to use a program like
filemon (http://www.sysinternals.com/ntw2k/utilities.shtml) to see what
process is accessing the LDF file.
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
|||"Aaron Bertrand [MVP]" <aaron@.TRASHaspfaq.com> wrote in message
news:ulucZdfHEHA.2876@.TK2MSFTNGP09.phx.gbl...
> The tables, or the log file? Sounds like both are happening.
Both, but the tables are the ones dropping/missing first.
Does drive caching has anything to do with it? The Windows Event Log
complaints that drive cache is disabled. I've temporary enable it and still
checking the results. But since no one has had this problem before, I'm not
certain of whether this is the solution or what is causing the tables to
drop or go missing.

> Once you get
> the system back where it should be, you might want to use a program like
> filemon (http://www.sysinternals.com/ntw2k/utilities.shtml) to see what
> process is accessing the LDF file.
I've downloaded the utility but could not find any process out of the
extraordinary.
Steven Ung
"The source of all greatness lies within you" - Anonymous

Mysterious mystery -- 2002-11-08/2002-11-09

I have function that returns a table of information about properties. The
data comes from three different tables -- addresses (called PropertyID),
property characteristics, and events concerning those properties (sales,
appraisals, etc.), plus a table that maps one representation of property
types into another. The records are selected on the basis of location
(longitude & latitude), property type, event type, and a range of
event dates (upper and lower date specified). There are tens of millions
of records of all types, and almost any location, property type, event type
and date range will yield records.

The heart of it is a cursor that selects records from joins on this basis:

SELECT <a bunch of fields>
FROM Property d
JOIN PropTypeMap ptm ON ptm.PropertyTypeID = d.PropertyTypeID
JOIN PropertyID a ON a.PropID = d.PropID
JOIN Event e1 ON e1.PropID = d.PropID
LEFT OUTER JOIN Event e2 ON e2.PropID = d.PropID
WHERE
d.LastSaleDate >= @.LoDate
AND a.GeoLongitude BETWEEN @.LowerLon AND @.UpperLon
AND a.GeoLatitude BETWEEN @.LowerLat AND @.UpperLat
AND ptm.PropCategory = @.PropType
AND a.GeoMatch <= @.MinGeoQuality

AND e1.EventTypeID = @.SaleEventType
AND e1.TransactionType = 'R'
AND e1.EventDt BETWEEN @.LoDate AND @.HiDate
AND e1.EventAmt > 0

AND e2.EventTypeID = @.AssessmentEventType
AND e2.EventDt <= @.HiDate
AND e2.EventAmt > 0

Each property has one PropertyID record, one Property record, and N Event
records (average perhaps five).

What is the mystery? If @.HiDate, which is the upper end of the time window,
is 2002-11-08 or earlier, nothing is returned. If it's 2002-11-09 or later,
oodles of records are found. I get the same query plan for either one, and
based on the content of the data, they should return almost exactly the same
set of records -- exactly the same set in almost all cases, in fact.

Is 2002-11-08/09 some sort of magic dividing point? I have replicated this
on the large database and on a smaller test version on another SQL Server.
(SQL Server 2000) I dropped the indexes and tried it, and
the same thing happened. This is driving me crazy![posted and mailed, please reply in news]

Jim Geissman (jim_geissman@.countrywide.com) writes:
> What is the mystery? If @.HiDate, which is the upper end of the time
> window, is 2002-11-08 or earlier, nothing is returned. If it's
> 2002-11-09 or later, oodles of records are found. I get the same query
> plan for either one, and based on the content of the data, they should
> return almost exactly the same set of records -- exactly the same set in
> almost all cases, in fact.
> Is 2002-11-08/09 some sort of magic dividing point? I have replicated
> this on the large database and on a smaller test version on another SQL
> Server. (SQL Server 2000) I dropped the indexes and tried it, and the
> same thing happened. This is driving me crazy!

Without access to the database, or a script that reproduces the problem,
there is much left for me, but to guess.

And the obvious guess is that the rows you find are from 2002-11-08, but
have a time porttion, and thus are > '2002-11-08 00:00:00'.

However, I notice one thing with your query which may not be correct:

LEFT OUTER JOIN Event e2 ON e2.PropID = d.PropID
WHERE ...
AND e2.EventTypeID = @.AssessmentEventType
AND e2.EventDt <= @.HiDate
AND e2.EventAmt > 0

The idea with a left outer join is that you include rows in the left
table, even if there is no matching rows in the right table. The
columns in the right table are then set to NULL.

Now, the FROM clause is (logically) evaluated before the WHERE clause,
which acts on the filter on the table defined by the FROM clause. This
means that you will filter away those rows with NULL in e2.EventTypeID
that comes from the outer join. Your join is now effectively an inner
join.

There are two ways to handle this:
1) Add conditions with OR clauses or coalesce to handle NULL in the WHERE
clause.
2) Move the conditions to the ON clause.

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||Thanks, Erland. You hit the nail on the head. I was naively assuming that
the right side of the Left Outer Join didn't matter, but when I removed the
second condition in the excerpt below, the records all appeared. As you
said, it was because the FROM was being evaluated before the WHERE. Moving
the condition to ON fixed it. Thanks. I wonder if I have any other
scripts that make this mistake...

> However, I notice one thing with your query which may not be correct:
> LEFT OUTER JOIN Event e2 ON e2.PropID = d.PropID
> WHERE ...
> AND e2.EventTypeID = @.AssessmentEventType
> AND e2.EventDt <= @.HiDate
> AND e2.EventAmt > 0
> The idea with a left outer join is that you include rows in the left
> table, even if there is no matching rows in the right table. The
> columns in the right table are then set to NULL.
> Now, the FROM clause is (logically) evaluated before the WHERE clause,
> which acts on the filter on the table defined by the FROM clause. This
> means that you will filter away those rows with NULL in e2.EventTypeID
> that comes from the outer join. Your join is now effectively an inner
> join.
> There are two ways to handle this:
> 1) Add conditions with OR clauses or coalesce to handle NULL in the WHERE
> clause.
> 2) Move the conditions to the ON clause.|||Jim Geissman (jim_geissman@.countrywide.com) writes:
> Thanks, Erland. You hit the nail on the head. I was naively assuming
> that the right side of the Left Outer Join didn't matter, but when I
> removed the second condition in the excerpt below, the records all
> appeared. As you said, it was because the FROM was being evaluated
> before the WHERE. Moving the condition to ON fixed it. Thanks. I
> wonder if I have any other scripts that make this mistake...

A very common mistake to make. I recall that I did it myself a few
times when I switched to the new syntax from the old *= crap.

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

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

Mysterious loss of data from mssql2k

Hi All,

I'm trying to track down a mysterious problem we're experiencing in
which updates and inserts to tables in our mssql2k server appear to be
'disappearing.'

To explain our situation:

We have a web page (written in ASP, if that's relevant) on which we
accept enrollment information.

When that page is submitted, the form data is passed to a stored
procedure on our mssql2k server, which performs several operations,
all of which are wrapped in a transaction.

In particular, the stored procedure performs an update operation on a
record in one table (i'll call it TableA) and an insert into another
table (TableB).

If the procedure encounters a problem (ie after each update / insert
operation in the procedure we test for IF @.@.Error<>0) it performs a
rollback, performs a select similar to the one immediately below, and
then RETURNs.

SELECT '1' as error, 'Unable to update TableA' as errormsg

If the procedure doesn't fail any of the @.@.Error tests, the
transaction is committed, and a membership number is SELECTed to be
returned.

SELECT '0' as error, @.memnum as membershipnumber

The @.memnum variable is populated within the transaction.

Back in the ASP page we test both for the proc returning an empty
recordset, or for it passing an explicit value in the error field, and
push the page to an error page if either of these conditions are met.

If, on the other hand, none of these conditions are met, and the
membershipnumber field in the recordset is populated with a valid
membership number, we push to a confirmation page.

This confirmation page receives the membership number in a session
variable, performs a SELECT against TableB (the table that received
the insert during the proc) using that membership number in the WHERE
clause, and the resultant recordset is used to populate the
confirmation details on that page. That recordset is also then used to
populate the details of a confirmation email, which is automatically
sent by the confirmation page.

And now here's our problem: we've become aware of a handfull of people
who have gone through the enrollment process, have received the
confirmation email containing the information they supplied as
expected, but the data appears to be entirely missing from our tables.
By that I mean that the record in TableA does not appear to have been
updated (under normal circumstances that record should have had
several flags set, and several other fields updated with information
supplied by the person enrolling), and the record in TableB does not
appear to have been inserted.

In essence, looking at our tables, it *feels* like the transaction in
the stored procedure for that particular enrollment hit a problem and
was rolled back. However, the evidence that we have in the form of the
confirmation email argues strongly that the data must have existed in
our tables (particularly in TableB), if only for an unknown period of
time.

We're kind of at our wit's end to work out what is going wrong with
these enrollments. From my understanding of transactions (and I could
well be wrong) any changes to data (ie updates, inserts etc) contained
within are essentially 'invisible' to any other operation (ie the
SELECT that happens in the confirmation page) until the transaction is
committed, implying that the effect of the update and insert should
have been 'permanently' successful if no error code is received and if
a valid membership number was returned. I ask, because someone in our
team has suggested that maybe the operations in the transaction
'lasted long enough' in the tables to have been visible for the SELECT
on the confirmation page to have worked, but were then subsequently
rolled back, explaining why the confirmation email is appropriately
populated and why the data then appears to be missing. However, as I
said, this doesn't match my understanding of how transactions behave.

Sorry for the length of this post, but I felt it was best to explain
this as best as I could.

Does anyone have any advice they can give us on this situation? ie,
are there any known problems with operations in transactions 'bleeding
over' into tables, but then being rolled back at some later point?
Does anyone have any thoughts or suggestions on how we can further
diagnose this issue?

Truly, any help will be immensely appreciated...

Thanks in advance,

M Wells"M Wells" <planetthoughtful@.gmail.com> wrote in message
news:hmba41p1gvtsmudtbus027ad3rapgo1ghd@.4ax.com...
> Hi All,
> I'm trying to track down a mysterious problem we're experiencing in
> which updates and inserts to tables in our mssql2k server appear to be
> 'disappearing.'
> To explain our situation:
> We have a web page (written in ASP, if that's relevant) on which we
> accept enrollment information.

<snip
First, to address your question about data inside a transaction being
visible to other connections, this would only happen if the other connection
explicitly sets its transaction level to READ UNCOMMITTED, which would allow
it to see data which has been inserted/updated but not committed. See SET
TRANSACTION ISOLATION LEVEL in Books Online for more details - I suppose
your ASP connections could be setting this isolation level, but it isn't the
default, so it would be somewhat unusual.

As for tracking down what's going on with the data, you can use Profiler to
run a trace, perhaps filtered on those specific tables and any relevant
stored procedures. If this problem happens fairly often, then running it
interactively may be possible, otherwise see the sp_trace_% procs in Books
Online for details of setting up a server-side trace.

You might also want to check for any triggers on the tables, as sometimes
they can be fired at times you don't expect. And if you have a middle tier
layer, you could also see if it's initiating a transaction before calling
the procedure - it could be that the procedure itself commits correctly, and
the email is sent, but there's an additional outer transaction started by
the middle tier which is then sometimes rolled back after sending the email.
Checking @.@.TRANCOUNT inside the procedure would give you a clue.

Simon|||M Wells (planetthoughtful@.gmail.com) writes:
> If the procedure doesn't fail any of the @.@.Error tests, the
> transaction is committed, and a membership number is SELECTed to be
> returned.
> SELECT '0' as error, @.memnum as membershipnumber
> The @.memnum variable is populated within the transaction.
> Back in the ASP page we test both for the proc returning an empty
> recordset, or for it passing an explicit value in the error field, and
> push the page to an error page if either of these conditions are met.
> If, on the other hand, none of these conditions are met, and the
> membershipnumber field in the recordset is populated with a valid
> membership number, we push to a confirmation page.
> This confirmation page receives the membership number in a session
> variable, performs a SELECT against TableB (the table that received
> the insert during the proc) using that membership number in the WHERE
> clause, and the resultant recordset is used to populate the
> confirmation details on that page. That recordset is also then used to
> populate the details of a confirmation email, which is automatically
> sent by the confirmation page.
> And now here's our problem: we've become aware of a handfull of people
> who have gone through the enrollment process, have received the
> confirmation email containing the information they supplied as
> expected, but the data appears to be entirely missing from our tables.

As I understand, this is an intermittent problem, and you don't have a
reproducible scenario. This make such a problem much more difficult
to track down. And if you make changes to address, you cannot really
be sure that you fixed the right thing.

One thing that is not clear to me is whether it is the same SQL Server
process that runs the stored procedure and the gets the data to the
confirmation page, or whether they are two different. (I should butt
in that I don't know ASP or IIS, so this talk about session variables
etc, tells me little.)

If it is the same SQL Server process, here is something that could
happen:

1) The stored procedure first run unsuccessfully, and a transaction
is started, but then neither committed nor rolled back.
2) The process then runs the procedure successfully, and then gets
the data to the confirmation page. This time a nested transaction
was started and committed. However, "commit" in the case of an
inner transaction just means that transaction count is decremented.
3) The process goes on and registers and confirms more enrollments.
4) Eventually the process is logged out, still with an open transaction.
All enrollments are now rolled back.

So why in step 1, would this happen? It can be a coding error in
the stored procedure, so that a rollback is not executed when it
should. But it could also be a client-side thing. Say that the
procedure is blocked for some reason, and the client gets a command
timeout. In this case the transaction started by the stored procedure
is *not* rolled back. This a really nasty gotcha.

If the confirmation page is really a separate SQL Server connection -
and you should really use the SQL Server Profiler to verify this - then
the data has been committed, and thus it has later been removed. Well,
if the confirmation reads with NOLOCK, are back to the previous
scenario.

One thing you should investigate in either case, is whether these missing
enrollments happened at different points in time, or if they are clustered.
That could give a clue of what may have happened.

I hope this has given you some more ideas of what to look for.

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

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

Mysterious indexes "_WA_Sys_..."

I was looking for tables with no indexes, and I keep
finding entries in sysindexes with names
like "_WA_Sys_....", which I certainly don't create.
The last one is possibly attached to a column defined as
nvarchar(128), but its the only column in the table
defined that way, and the other columns don't have such an
index ! very confusing.
Does anyone know what these are ?
Does anyone have an SQL script that will correctly!
identify tables without indexes ? This would be hugely
appreciated !_WA_Sys_...." are SQL Server statstics. You have AUTO Stats turned on.
This is expected. You should leave them alone.
"Jim Trowbridge" <jtrowbridge@.adelaidebank.com.au> wrote in message
news:07be01c36600$78857070$a401280a@.phx.gbl...
I was looking for tables with no indexes, and I keep
finding entries in sysindexes with names
like "_WA_Sys_....", which I certainly don't create.
The last one is possibly attached to a column defined as
nvarchar(128), but its the only column in the table
defined that way, and the other columns don't have such an
index ! very confusing.
Does anyone know what these are ?
Does anyone have an SQL script that will correctly!
identify tables without indexes ? This would be hugely
appreciated !

Monday, March 12, 2012

mysql to ms sql

Need a little help. I am a newbie with both databases (mysql and mssql). I
am transferring from mysql to ms sql. There are very few tables and data.
I am basically transferring structure by hand.
I am finding the syntax to be difficult to deal with. I have a txt file
with several tables and their attributes from mysql but I am not finding the
exact same thing in ms sql. I wonder if someone can look at the code and
give me a hand. I am using the EM to put this on ms sql online.
Here is an example of one table and the trouble I am having with it. This
is the mysql code to be changed. Please see my comments under this code.
CREATE TABLE room_action (
id varchar(100) NOT NULL default '',
room tinyint(3) unsigned NOT NULL default '0',
user tinyint(3) unsigned NOT NULL default '0',
name varchar(50) NOT NULL default '',
cmd varchar(10) NOT NULL default '',
x mediumint(9) defaulnamet '0',
y mediumint(9) default '0',
msg varchar(255) default NULL,
avatar tinyint(3) unsigned default NULL,
viewed tinyint(3) unsigned NOT NULL default '0',
PRIMARY KEY (id)
) TYPE=MyISAM;
I am creating the table in the EM. I am assuming that the numbers are the
field length. For example:
room tinyint(3) unsigned NOT NULL default '0'
I am attempting to put 3 in the length but it will only use 1.
I also am confused about unsigned. Also what is TYPE=MyISAM
Can anyone give me a hand?
Thanks
Laura KLaura,
Try this:
CREATE TABLE room_action (
id varchar(100) NOT NULL default '',
room smallint NOT NULL default 0,
userID smallint NOT NULL default 0, --user is a keyword, change to
userID
name varchar(50) NOT NULL default '',
cmd varchar(10) NOT NULL default '',
x integer default 0,
y integer default 0,
msg varchar(255) default NULL,
avatar smallint default NULL, --use a default of 0 instead of null if
possible, will prevent aggreatation warnings
viewed smallint NOT NULL default 0,
PRIMARY KEY (id)
)
Also, please consider removing the default '' on your not null columns. It
is contradictory and a pain in the rear to maintain.
Take some time to review Books On Line, especially data types, as many of
your conversion questions will be answered.
--Morgan
"Laura K" <klkazanAT@.ATcharter.net> wrote in message
news:%23Gz90CleDHA.1824@.TK2MSFTNGP10.phx.gbl...
> Need a little help. I am a newbie with both databases (mysql and mssql).
I
> am transferring from mysql to ms sql. There are very few tables and data.
> I am basically transferring structure by hand.
> I am finding the syntax to be difficult to deal with. I have a txt file
> with several tables and their attributes from mysql but I am not finding
the
> exact same thing in ms sql. I wonder if someone can look at the code and
> give me a hand. I am using the EM to put this on ms sql online.
> Here is an example of one table and the trouble I am having with it. This
> is the mysql code to be changed. Please see my comments under this code.
> CREATE TABLE room_action (
> id varchar(100) NOT NULL default '',
> room tinyint(3) unsigned NOT NULL default '0',
> user tinyint(3) unsigned NOT NULL default '0',
> name varchar(50) NOT NULL default '',
> cmd varchar(10) NOT NULL default '',
> x mediumint(9) defaulnamet '0',
> y mediumint(9) default '0',
> msg varchar(255) default NULL,
> avatar tinyint(3) unsigned default NULL,
> viewed tinyint(3) unsigned NOT NULL default '0',
> PRIMARY KEY (id)
> ) TYPE=MyISAM;
>
> I am creating the table in the EM. I am assuming that the numbers are the
> field length. For example:
> room tinyint(3) unsigned NOT NULL default '0'
> I am attempting to put 3 in the length but it will only use 1.
> I also am confused about unsigned. Also what is TYPE=MyISAM
> Can anyone give me a hand?
> Thanks
> Laura K
>|||Thanks but I don't want to do mySQL. The original program was written for a
mysql database but we want to run it from MS sql. I am writing the tables
by hand in ms sql but I do not know much about the differences.
Laura
"Groucho" <rog11228@.aol.com> wrote in message
news:eFKpYqleDHA.4024@.TK2MSFTNGP11.phx.gbl...
> "Laura K" wrote in message
> > Need a little help. I am a newbie with both databases (mysql and
mssql).
> .
> .
> Don't expect to much help in the way of MySql here.
> It's not considered a *real* rdbms in these parts:)
> There are many differences/similarities between the two.
> You'll get Mysql help on google at:
> mailing.database.mysql
> mailing.database.mysql-win32
> You can also let MySql utilities help you,especially the ones that
> import and export data.Check out:
> SQLyog @.
> www.webyog.com
> and
> MySql GUI tool @.
> www.mysqlgui.net
> Install the MySql odbc driver and you can use the
> Server dts utility to transfer data and see how the
> table structure(s) turn out.
> A type MyISAM is a particular type of MySql table.
> In MySql there are different types of tables you can use.
> This concept does not exist in Server.See the MySql
> docs for details.
> It also matters what version of MySql your working with.
> Check their website for details.(You should be using 4.0.xx).
> If you want subqueries,derived tables and some other
> fancy server like constructs check out 4.1 alpha.
> Using both Server and MySql will probably become
> pretty common as time goes on.You can pick the one
> you want to pay for:).
> RAC v2.2 and QALite for Sql Server released.
> www.rac4sql.net
>
>|||Thanks so much. I am beginning the understand the differences.
I did a search for conversion but all I got all kinds of non helpful things
instead from the search engines. I will take a look at books online.
Thanks again for the detailed help.
Laura
"Morgan" <mfears@.spamcop.net> wrote in message
news:OaAQiGmeDHA.3528@.tk2msftngp13.phx.gbl...
> Laura,
> Try this:
> CREATE TABLE room_action (
> id varchar(100) NOT NULL default '',
> room smallint NOT NULL default 0,
> userID smallint NOT NULL default 0, --user is a keyword, change to
> userID
> name varchar(50) NOT NULL default '',
> cmd varchar(10) NOT NULL default '',
> x integer default 0,
> y integer default 0,
> msg varchar(255) default NULL,
> avatar smallint default NULL, --use a default of 0 instead of null if
> possible, will prevent aggreatation warnings
> viewed smallint NOT NULL default 0,
> PRIMARY KEY (id)
> )
> Also, please consider removing the default '' on your not null columns. It
> is contradictory and a pain in the rear to maintain.
> Take some time to review Books On Line, especially data types, as many of
> your conversion questions will be answered.
> --Morgan
>
> "Laura K" <klkazanAT@.ATcharter.net> wrote in message
> news:%23Gz90CleDHA.1824@.TK2MSFTNGP10.phx.gbl...
> > Need a little help. I am a newbie with both databases (mysql and
mssql).
> I
> > am transferring from mysql to ms sql. There are very few tables and
data.
> > I am basically transferring structure by hand.
> >
> > I am finding the syntax to be difficult to deal with. I have a txt file
> > with several tables and their attributes from mysql but I am not finding
> the
> > exact same thing in ms sql. I wonder if someone can look at the code
and
> > give me a hand. I am using the EM to put this on ms sql online.
> >
> > Here is an example of one table and the trouble I am having with it.
This
> > is the mysql code to be changed. Please see my comments under this code.
> >
> > CREATE TABLE room_action (
> > id varchar(100) NOT NULL default '',
> > room tinyint(3) unsigned NOT NULL default '0',
> > user tinyint(3) unsigned NOT NULL default '0',
> > name varchar(50) NOT NULL default '',
> > cmd varchar(10) NOT NULL default '',
> > x mediumint(9) defaulnamet '0',
> > y mediumint(9) default '0',
> > msg varchar(255) default NULL,
> > avatar tinyint(3) unsigned default NULL,
> > viewed tinyint(3) unsigned NOT NULL default '0',
> > PRIMARY KEY (id)
> > ) TYPE=MyISAM;
> >
> >
> > I am creating the table in the EM. I am assuming that the numbers are
the
> > field length. For example:
> > room tinyint(3) unsigned NOT NULL default '0'
> >
> > I am attempting to put 3 in the length but it will only use 1.
> >
> > I also am confused about unsigned. Also what is TYPE=MyISAM
> >
> > Can anyone give me a hand?
> >
> > Thanks
> >
> > Laura K
> >
> >
>