Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Thursday, March 22, 2012

Deadlock Question

Hi All,

Can multiple updates on one table using single
query generate deadlock ?
For example, at the same time, there are 2 users
run 2 queries as follows :

User1 runs :
update tab1 set tab1.v = tab1.v + 1
from tab1 inner join tab2 on tab1.no = tab2.no

User2 runs :
update tab1 set tab1.v = tab1.v + 1
from tab1 inner join tab3 on tab1.no = tab3.no

Note :
The content of the column "no" on table tab2 :
('A','B','C',...,'X','Y','Z')
The content of the column "no" on table tab3
is like in table tab2, but in different order :
('Z','Y','X',....,'C','B','A')

Thanks in advance

Anita Hery

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Anita (anonymous@.devdex.com) writes:
> Can multiple updates on one table using single
> query generate deadlock ?
> For example, at the same time, there are 2 users
> run 2 queries as follows :
> User1 runs :
> update tab1 set tab1.v = tab1.v + 1
> from tab1 inner join tab2 on tab1.no = tab2.no
> User2 runs :
> update tab1 set tab1.v = tab1.v + 1
> from tab1 inner join tab3 on tab1.no = tab3.no
> Note :
> The content of the column "no" on table tab2 :
> ('A','B','C',...,'X','Y','Z')
> The content of the column "no" on table tab3
> is like in table tab2, but in different order :
> ('Z','Y','X',....,'C','B','A')

Tables in a relational database are sets, and data has no order.

But, of course, for the evaluation of a query the physical order may
affect such things as deadlock.

Anyway, I am not going to answer the question directly, because there
is a lot of unknown elements. Is tbl.v a primary key or at least
indexed? What about tbl2.no and tbl3.no? And what exactly is
different order?

CREATE TABLE statements for the tables and INSERT statemetns for the
data may help.

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

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

Thanks for your reply.

Deadlock can be found easily in several command steps.
But, how can I find it in multiple updates using
only one step of command ?

This question is posted because I do not know
exactly how SQL Server handles my sample query.
And I become worry after reading many deadlock
articles here. Especially deadlock that is caused
by table index.

Below is the description of the tables :

Table tb1 :
- no CHAR(10); no2 CHAR(10); v INT
- Index possibility : only one index, on no or on no2
- no is unique, no2 is unique
- v is not a key.

Table tb2 :
- x CHAR(10); no CHAR(10)
- Index : on x
- x is not unique, no is unique

Table tb3 :
- x CHAR(10); no CHAR(10)
- Index : on x
- x is not unique, no is unique

Regards,

Anita Hery

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Anita (anonymous@.devdex.com) writes:
> Deadlock can be found easily in several command steps.
> But, how can I find it in multiple updates using
> only one step of command ?

Testing deadlocks that may occur from single statements are indeed not
trivial to construct at will.

One possibility is to write a small app - could even be a stored procedure
- that runs the supicious SQL statement all over again in an infinite
loop. If you get a deadlock, you now know that it can happen. If you
don't get a deadlock - well you still don't know, because may the test
was not good enough.

Another approach is to introduce a waitstate somewhere, so that you get
a chance to start a second query window with the competing query. This
is not trivial either. For a simple case, I used this function some
time ago:

create function nisse () returns int as
begin
exec master..xp_cmdshell 'osql -E -n -Q "WAITFOR DELAY ''00:00:20''"'
return 1
end

In your case, at least one your updates should read:

UPDATE tbl
SET col = dbo.nisse() -- Or some expression including dbo.nisse().
...

But of course, this constructs a situation which is not really the same
as the real-world scenario, and the observations may not be transferrable.
(But it seems to me that in this case, they could.)

Since you did not provide CREATE TABLE statements and INSERT statements
with sample data, I was too lazy to actually try this technique with
your example. :-)

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

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||When SQL Server receive query :
update tab1 set tab1.v = tab1.v + 1
from tab1 inner join tab2 on tab1.no = tab2.no
I expect it follows the procedure like this :
a. Find the rows that will be updated.
b. If they are not found then exit.
c. Try locking the rows found.
d. If locking is successfull then update the
rows and exit.
e. Wait for miliseconds.
f. If query timeout expires then exit.
g. goto c.

Since I do not have information about how SQL Server
handles the query, I usually insert tablock hint in the query :
update tab1 with (tablock) set tab1.v = tab1.v + 1
from tab1 inner join tab2 on tab1.no = tab2.no

Though by using tablock hint it will lock all rows
in the table (prevent other rows from being updated
by other users) but, I think I should take this way.
It is free from deadlock.

Anita Hery

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Anita (anonymous@.devdex.com) writes:
> When SQL Server receive query :
> update tab1 set tab1.v = tab1.v + 1
> from tab1 inner join tab2 on tab1.no = tab2.no
> I expect it follows the procedure like this :
> a. Find the rows that will be updated.
> b. If they are not found then exit.
> c. Try locking the rows found.
> d. If locking is successfull then update the
> rows and exit.
> e. Wait for miliseconds.
> f. If query timeout expires then exit.
> g. goto c.

I have to admit that I don't fully master the internal procedure, but
I would expect it to be somewhat different. I would expect that already
when SQL Server finds the matching rows that it applies at least
shared locks, possible also intent locks. Once a row is found to
qualify, I would suppose SQL Server puts an exclusive lock on a
row.

You mention "query timeout". I suppose you mean lock timeout, which you
control with SET LOCK_TIMEOUT. Query timeout is a client (mis)feature,
and does not affect locking.

Going back to your original post, you had these two statements:

User1 runs :
update tab1 set tab1.v = tab1.v + 1
from tab1 inner join tab2 on tab1.no = tab2.no

User2 runs :
update tab1 set tab1.v = tab1.v + 1
from tab1 inner join tab3 on tab1.no = tab3.no

Working from my assumptions above - which I like to stress are nothing
but assumptions, you could get a deadlock here, if the statistics on
the table are such that the optimizer chooses different query plans.
For instance, for the first query, the optimizer decides to scan tab1
and then perform a nested join with tab2. But for the second query,
the optimizer scans tab3, and performs a nested join with index seek
on tab1. If the two queries start at the same time, they will find
matching rows in tab1 in different order, and therefor they will
deadlock.

> Since I do not have information about how SQL Server
> handles the query, I usually insert tablock hint in the query :
> update tab1 with (tablock) set tab1.v = tab1.v + 1
> from tab1 inner join tab2 on tab1.no = tab2.no
> Though by using tablock hint it will lock all rows
> in the table (prevent other rows from being updated
> by other users) but, I think I should take this way.
> It is free from deadlock.

Yes, this should be deadlock free. But there are of course other issues
with tablock. If most updates are on single rows, tablock might be too
heavy-handed and lead to concurrency issues.

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

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

Thanks for your reply,

Yes, your assumption is somewhat different with what I expect. I expect
: if there are 10 matching rows and SQL Server can lock only 9 rows,
then : SQL Server unlock 9 rows, wait for a moment, and try locking 10
rows again.
If my expectation is true, then the query is deadlock free and I will
avoid using tablock hint.

My last question is where I can get information that tell us your
assumption or my expectation is true ?

Regards,
Anita Hery

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!|||Anita (anonymous@.devdex.com) writes:
> Yes, your assumption is somewhat different with what I expect. I expect
>: if there are 10 matching rows and SQL Server can lock only 9 rows,
> then : SQL Server unlock 9 rows, wait for a moment, and try locking 10
> rows again.
> If my expectation is true, then the query is deadlock free and I will
> avoid using tablock hint.
> My last question is where I can get information that tell us your
> assumption or my expectation is true ?

So much I can tell with confidence, that SQL Server never releases locks
because it cannot get all locks it needs to carry out a task. While such
a strategy could reduce deadlock, it could have other nasty effects like
lock starvation. A process that needs to access many rows in a busy system
would never get all locks.

Also, I believe that the work order is something like: lock one row,
update that row, lock next row and so on. In this case, it is of course
even less possible to release rows.

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

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

Thanks for all your replies.

Regards,
Anita Hery

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Wednesday, March 21, 2012

Deadlock Manager

In what appears to be a deadlock scenario, why doesn’t the deadlock manage
r engage and determine a victim?
Here is an example of what I am talking about:
Query 1
Select statement on table "A" with a suitable where clause to define only th
e records desired.
Query 2
Multiple insert statements within a single transaction to several different
tables including table "A."
The resulting scenario is that query 2 has crossed the magic threshold of 12
50 locks and therefore escalates its lock to a table lock. Query 1, which is
now blocked, also escalates to a table lock. The two queries then sit aroun
d waiting for each other to
finish, but they never do.
Here are my questions:
The lock manager will begin escalation if a single resource is using more th
an 1250 locks on table resources, or 765 locks on index resources. If the ma
chine in question has 2GB of physical memory, how big is the memory pool for
locks?
Even though this isn't the classic deadlock scenario, why doesn't the deadlo
ck manager recognize this as a deadlock and choose a victim to help free up
the resources?
Thanks.> The lock manager will begin escalation if a single resource is using more
than 1250 locks on table resources, or 765 locks on index resources. If the
machine in question has 2GB of physical memory, how big is the memory pool
for locks?
>
If default not changed, it is 40% of memory allocated.

> Even though this isn't the classic deadlock scenario, why doesn't the
deadlock manager recognize this as a deadlock and choose a victim to help
free up the resources?
>
Since your situation is not a deadlock (it is a block), it will try to
finish the first (blocking) process. Deadlock does not have any hope of
finishing, and therefore sql server has the mechanism of getting itself out
of it.
Quentin

Deadlock Manager

In what appears to be a deadlock scenario, why doesn’t the deadlock manager engage and determine a victim?
Here is an example of what I am talking about:
Query 1
Select statement on table "A" with a suitable where clause to define only the records desired.
Query 2
Multiple insert statements within a single transaction to several different tables including table "A."
The resulting scenario is that query 2 has crossed the magic threshold of 1250 locks and therefore escalates its lock to a table lock. Query 1, which is now blocked, also escalates to a table lock. The two queries then sit around waiting for each other to
finish, but they never do.
Here are my questions:
The lock manager will begin escalation if a single resource is using more than 1250 locks on table resources, or 765 locks on index resources. If the machine in question has 2GB of physical memory, how big is the memory pool for locks?
Even though this isn't the classic deadlock scenario, why doesn't the deadlock manager recognize this as a deadlock and choose a victim to help free up the resources?
Thanks.
> The lock manager will begin escalation if a single resource is using more
than 1250 locks on table resources, or 765 locks on index resources. If the
machine in question has 2GB of physical memory, how big is the memory pool
for locks?
>
If default not changed, it is 40% of memory allocated.

> Even though this isn't the classic deadlock scenario, why doesn't the
deadlock manager recognize this as a deadlock and choose a victim to help
free up the resources?
>
Since your situation is not a deadlock (it is a block), it will try to
finish the first (blocking) process. Deadlock does not have any hope of
finishing, and therefore sql server has the mechanism of getting itself out
of it.
Quentin

Monday, March 19, 2012

Deadlock in Queue

Hello!

I am running a basic SSB queue setup (more or less the Hello World example)and running into the following error message:

Transaction (Process ID 120) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

At first, I thought it was because I had the Initiator and Target Services on the same Queue, but I get this error even when I separate the two Services onto two Queues. This happens when I run more than one Target application receiving messages from the Target Queue.

Does anybody have any idea what could be happening here? Am I not allowed to set up more than one receiver?

Thanks --

Robert

OK, after reading a bit more, I think that I may have found the answer.

When I called RECEIVE, I wasn't specifying the conversation handle or conversation group ID. I changed my query to utilize the GET CONVERSATION GROUP statement to get the first conversation group ID on the receive Queue, then only RECEIVE the messages within the conversation group.

So far, I haven't had a deadlock, but I intend to leave this running for a while to see if it comes back. Does what I found seem like it would make sense or is there anything else that I may not be taking into account?

|||That makes perfect sense. whatever you receive off the queue is then locked (By conversation group) while you are handling it. If you have two receive processes running off the same queue if they try to process the same conversation group a deadlock will occur.

Deadlock in Queue

Hello!

I am running a basic SSB queue setup (more or less the Hello World example)and running into the following error message:

Transaction (Process ID 120) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction.

At first, I thought it was because I had the Initiator and Target Services on the same Queue, but I get this error even when I separate the two Services onto two Queues. This happens when I run more than one Target application receiving messages from the Target Queue.

Does anybody have any idea what could be happening here? Am I not allowed to set up more than one receiver?

Thanks --

Robert

OK, after reading a bit more, I think that I may have found the answer.

When I called RECEIVE, I wasn't specifying the conversation handle or conversation group ID. I changed my query to utilize the GET CONVERSATION GROUP statement to get the first conversation group ID on the receive Queue, then only RECEIVE the messages within the conversation group.

So far, I haven't had a deadlock, but I intend to leave this running for a while to see if it comes back. Does what I found seem like it would make sense or is there anything else that I may not be taking into account?

|||That makes perfect sense. whatever you receive off the queue is then locked (By conversation group) while you are handling it. If you have two receive processes running off the same queue if they try to process the same conversation group a deadlock will occur.

Thursday, March 8, 2012

Deactivating Admin and Domain-Admins

Hello,

is it possible to deactivate the groups admins and domain-admins in sql server without getting in trouble with the sql-server. For example when the system boots the program should start normally without any problems.

We want do deactivate the accounts because we have some critical information in sql server and dont want to give all admins the possibility to have a look at these data.

We just want to have sa within the role sysadmin.

Regards
Franz

You can drop the BUILTIN\Adminstrators group from the sql logins. Make sure you have the password to sa as you don't want to leave yourself with no sysadmin login.

Remember, if you're using SQL Agent, the service account it runs under does need to be a sysadmin in sql.

HTH!

|||Thank you for the answer.

Yes we are using the SQL Agent. If i give the account the role sysadmin, an administrator has the possibility to give it an new password and can then see all information.

Is there really no chance to deactivate the accounts?

We also have an SQL Cluster is there any further account needed?

If i have no chance to deactivate those accounts generally without giving some special acoounts the sysadmin role, is it a method to deactivate the accounts and when i have to reboot or start the services to give them temporarely the sysadmin role?

Regards
Franz
|||

The SQL Agent Service is a sysadmin by design. In a future version we may be able to modify the design to make SQL Agent not have to be a sysadmin but that doesn't help you today.

Removing builtin\administrator is probably the best you can do.

HTH,

-Steven Gott

SDE/T

SQL Server

Wednesday, March 7, 2012

DCOM for SQL 2000 debugging on 2003 server

Hi,
Anyone know how to configure DCOM for SQL debugging (i.e stepping through
stored procedure for example) on 2003 server ?
The following article explains how to configure for 2000 server but got
stuck on step 3 when attempting on 2003 server as option ( Distibuted COM
configuratin properties) not available.
http://msdn.microsoft.com/library/de...ldebugging.asp
Thanks for any information.
Scott
note:
- using visual studio 2003 on XP pro client
- using sql 2000 standard edition
- using 2003 server standard edition
DCOM for SQL 2000 debugging on 2003 server
Hi
I think you can use the XP instructions.
John
"scott" wrote:

> Hi,
> Anyone know how to configure DCOM for SQL debugging (i.e stepping through
> stored procedure for example) on 2003 server ?
> The following article explains how to configure for 2000 server but got
> stuck on step 3 when attempting on 2003 server as option ( Distibuted COM
> configuratin properties) not available.
> http://msdn.microsoft.com/library/de...ldebugging.asp
> Thanks for any information.
> Scott
> note:
> - using visual studio 2003 on XP pro client
> - using sql 2000 standard edition
> - using 2003 server standard edition
>
> DCOM for SQL 2000 debugging on 2003 server
>
>
>
|||thanks for reply john, you are probably corerct. it also seems the version
of VS maybe the problem.
thanks for reply
scott
"the Academic/Professional version of Visual Studio doesnt
support debugging against SQL Server.
For SQL Debugging to work you will need one of the following versions:
Version SQL Debugging
--X--
Enterpise SQL Server & MSDE
Developer SQL Server & MSDE
Professional MSDE
Standard Not available
Academic Not available "

DCOM for SQL 2000 debugging on 2003 server

Hi,
Anyone know how to configure DCOM for SQL debugging (i.e stepping through
stored procedure for example) on 2003 server ?
The following article explains how to configure for 2000 server but got
stuck on step 3 when attempting on 2003 server as option ( Distibuted COM
configuratin properties) not available.
http://msdn.microsoft.com/library/d...qldebugging.asp
Thanks for any information.
Scott
note:
- using visual studio 2003 on XP pro client
- using sql 2000 standard edition
- using 2003 server standard edition
DCOM for SQL 2000 debugging on 2003 serverHi
I think you can use the XP instructions.
John
"scott" wrote:

> Hi,
> Anyone know how to configure DCOM for SQL debugging (i.e stepping through
> stored procedure for example) on 2003 server ?
> The following article explains how to configure for 2000 server but got
> stuck on step 3 when attempting on 2003 server as option ( Distibuted COM
> configuratin properties) not available.
> http://msdn.microsoft.com/library/d...qldebugging.asp
> Thanks for any information.
> Scott
> note:
> - using visual studio 2003 on XP pro client
> - using sql 2000 standard edition
> - using 2003 server standard edition
>
> DCOM for SQL 2000 debugging on 2003 server
>
>
>|||thanks for reply john, you are probably corerct. it also seems the version
of VS maybe the problem.
thanks for reply
scott
"the Academic/Professional version of Visual Studio doesnt
support debugging against SQL Server.
For SQL Debugging to work you will need one of the following versions:
Version SQL Debugging
--_--
Enterpise SQL Server & MSDE
Developer SQL Server & MSDE
Professional MSDE
Standard Not available
Academic Not available "

DCOM for SQL 2000 debugging on 2003 server

Hi,
Anyone know how to configure DCOM for SQL debugging (i.e stepping through
stored procedure for example) on 2003 server ?
The following article explains how to configure for 2000 server but got
stuck on step 3 when attempting on 2003 server as option ( Distibuted COM
configuratin properties) not available.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskconfiguringdcomforsqldebugging.asp
Thanks for any information.
Scott
note:
- using visual studio 2003 on XP pro client
- using sql 2000 standard edition
- using 2003 server standard edition
DCOM for SQL 2000 debugging on 2003 serverHi
I think you can use the XP instructions.
John
"scott" wrote:
> Hi,
> Anyone know how to configure DCOM for SQL debugging (i.e stepping through
> stored procedure for example) on 2003 server ?
> The following article explains how to configure for 2000 server but got
> stuck on step 3 when attempting on 2003 server as option ( Distibuted COM
> configuratin properties) not available.
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vsdebug/html/vxtskconfiguringdcomforsqldebugging.asp
> Thanks for any information.
> Scott
> note:
> - using visual studio 2003 on XP pro client
> - using sql 2000 standard edition
> - using 2003 server standard edition
>
> DCOM for SQL 2000 debugging on 2003 server
>
>
>|||thanks for reply john, you are probably corerct. it also seems the version
of VS maybe the problem.
thanks for reply
scott
"the Academic/Professional version of Visual Studio doesnt
support debugging against SQL Server.
For SQL Debugging to work you will need one of the following versions:
Version SQL Debugging
--­--
Enterpise SQL Server & MSDE
Developer SQL Server & MSDE
Professional MSDE
Standard Not available
Academic Not available "

Friday, February 24, 2012

dbreindex and change recovery model

Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
DBREINDEX), is there a way to programmtically change the db recovery model
to bulk-logged before this process runs, and then change it back to full at
the conclusion?
Example...?
Thanks.
Message posted via http://www.droptable.comCheck out ALTER DATABASE in the BOL.
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"The Gekkster via droptable.com" <forum@.nospam.droptable.com> wrote in
message news:4308fa21ddaf4db6b1242ec457edac5e@.SQ
droptable.com...
Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
DBREINDEX), is there a way to programmtically change the db recovery model
to bulk-logged before this process runs, and then change it back to full at
the conclusion?
Example...?
Thanks.
Message posted via http://www.droptable.com|||Yes
before...
alter database YourDatabase set Recovery BULK_LOGGED
after
alter database YourDatabase set Recovery Simple
or
alter database YourDatabase set Recovery Full
Depending on your cup of tea...
Enjoy
Peter
"The Gekkster via droptable.com" wrote:

> Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
> DBREINDEX), is there a way to programmtically change the db recovery model
> to bulk-logged before this process runs, and then change it back to full a
t
> the conclusion?
> Example...?
> Thanks.
> --
> Message posted via http://www.droptable.com
>|||Wow, that's easy. Thanks guys...
Message posted via http://www.droptable.com|||See "alter database" in BOL.
Example:
use master
go
alter database northwind
set recovery bulk_logged
go
AMB
"The Gekkster via droptable.com" wrote:

> Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
> DBREINDEX), is there a way to programmtically change the db recovery model
> to bulk-logged before this process runs, and then change it back to full a
t
> the conclusion?
> Example...?
> Thanks.
> --
> Message posted via http://www.droptable.com
>

dbreindex and change recovery model

Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
DBREINDEX), is there a way to programmtically change the db recovery model
to bulk-logged before this process runs, and then change it back to full at
the conclusion?
Example...?
Thanks.
Message posted via http://www.droptable.com
Check out ALTER DATABASE in the BOL.
Tom
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
..
"The Gekkster via droptable.com" <forum@.nospam.droptable.com> wrote in
message news:4308fa21ddaf4db6b1242ec457edac5e@.droptable.co m...
Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
DBREINDEX), is there a way to programmtically change the db recovery model
to bulk-logged before this process runs, and then change it back to full at
the conclusion?
Example...?
Thanks.
Message posted via http://www.droptable.com
|||Yes
before...
alter database YourDatabase set Recovery BULK_LOGGED
after
alter database YourDatabase set Recovery Simple
or
alter database YourDatabase set Recovery Full
Depending on your cup of tea...
Enjoy
Peter
"The Gekkster via droptable.com" wrote:

> Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
> DBREINDEX), is there a way to programmtically change the db recovery model
> to bulk-logged before this process runs, and then change it back to full at
> the conclusion?
> Example...?
> Thanks.
> --
> Message posted via http://www.droptable.com
>
|||Wow, that's easy. Thanks guys...
Message posted via http://www.droptable.com
|||See "alter database" in BOL.
Example:
use master
go
alter database northwind
set recovery bulk_logged
go
AMB
"The Gekkster via droptable.com" wrote:

> Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
> DBREINDEX), is there a way to programmtically change the db recovery model
> to bulk-logged before this process runs, and then change it back to full at
> the conclusion?
> Example...?
> Thanks.
> --
> Message posted via http://www.droptable.com
>

dbreindex and change recovery model

Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
DBREINDEX), is there a way to programmtically change the db recovery model
to bulk-logged before this process runs, and then change it back to full at
the conclusion?
Example...?
Thanks.
--
Message posted via http://www.sqlmonster.comCheck out ALTER DATABASE in the BOL.
--
Tom
----
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinpub.com
.
"The Gekkster via SQLMonster.com" <forum@.nospam.SQLMonster.com> wrote in
message news:4308fa21ddaf4db6b1242ec457edac5e@.SQLMonster.com...
Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
DBREINDEX), is there a way to programmtically change the db recovery model
to bulk-logged before this process runs, and then change it back to full at
the conclusion?
Example...?
Thanks.
--
Message posted via http://www.sqlmonster.com|||Yes
before...
alter database YourDatabase set Recovery BULK_LOGGED
after
alter database YourDatabase set Recovery Simple
or
alter database YourDatabase set Recovery Full
Depending on your cup of tea...
Enjoy
Peter
"The Gekkster via SQLMonster.com" wrote:
> Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
> DBREINDEX), is there a way to programmtically change the db recovery model
> to bulk-logged before this process runs, and then change it back to full at
> the conclusion?
> Example...?
> Thanks.
> --
> Message posted via http://www.sqlmonster.com
>|||Wow, that's easy. Thanks guys...
--
Message posted via http://www.sqlmonster.com|||See "alter database" in BOL.
Example:
use master
go
alter database northwind
set recovery bulk_logged
go
AMB
"The Gekkster via SQLMonster.com" wrote:
> Borrowing from Example 'E' in BOL for DBCC SHOWCONTIG (and modified to use
> DBREINDEX), is there a way to programmtically change the db recovery model
> to bulk-logged before this process runs, and then change it back to full at
> the conclusion?
> Example...?
> Thanks.
> --
> Message posted via http://www.sqlmonster.com
>

dbo-owner

when I run the same scripts twice with different users (all having db_owner
rights), the SQL server duplicates the objects (for example, the stored
procedures).
How can I avoid it . If I define "dbo." for each object , it will be ok ?
thanks
That should do it !
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
"ft" <ft@.discussions.microsoft.com> schrieb im Newsbeitrag
news:636B38A4-CFCB-44F5-9775-1717A2409A16@.microsoft.com...
> when I run the same scripts twice with different users (all having
> db_owner
> rights), the SQL server duplicates the objects (for example, the stored
> procedures).
> How can I avoid it . If I define "dbo." for each object , it will be ok ?
> thanks
>

dbo-owner

when I run the same scripts twice with different users (all having db_owner
rights), the SQL server duplicates the objects (for example, the stored
procedures).
How can I avoid it . If I define "dbo." for each object , it will be ok ?
thanksThat should do it !
HTH, Jens Suessmeyer.
--
http://www.sqlserver2005.de
--
"ft" <ft@.discussions.microsoft.com> schrieb im Newsbeitrag
news:636B38A4-CFCB-44F5-9775-1717A2409A16@.microsoft.com...
> when I run the same scripts twice with different users (all having
> db_owner
> rights), the SQL server duplicates the objects (for example, the stored
> procedures).
> How can I avoid it . If I define "dbo." for each object , it will be ok ?
> thanks
>

dbo-owner

when I run the same scripts twice with different users (all having db_owner
rights), the SQL server duplicates the objects (for example, the stored
procedures).
How can I avoid it . If I define "dbo." for each object , it will be ok ?
thanksThat should do it !
HTH, Jens Suessmeyer.
http://www.sqlserver2005.de
--
"ft" <ft@.discussions.microsoft.com> schrieb im Newsbeitrag
news:636B38A4-CFCB-44F5-9775-1717A2409A16@.microsoft.com...
> when I run the same scripts twice with different users (all having
> db_owner
> rights), the SQL server duplicates the objects (for example, the stored
> procedures).
> How can I avoid it . If I define "dbo." for each object , it will be ok ?
> thanks
>

Tuesday, February 14, 2012

DBMail

Is it possible to embed a image datatype into a EMail message using sp_Send_DBMail?

For example, my query would select a saved print screen image held in a SQL table as datatype image. I would prefer not to attach this image but rather have it print in the message section.

Thanks in advance.Hopefully you mean xp_sendmail

Sends a message and a query result set attachment to the specified recipients.

Syntax
xp_sendmail {[@.recipients =] 'recipients [;...n]'}
[,[@.message =] 'message']
[,[@.query =] 'query']
[,[@.attachments =] 'attachments [;...n]']
[,[@.copy_recipients =] 'copy_recipients [;...n]'
[,[@.blind_copy_recipients =] 'blind_copy_recipients [;...n]'
[,[@.subject =] 'subject']
[,[@.type =] 'type']
[,[@.attach_results =] 'attach_value']
[,[@.no_output =] 'output_value']
[,[@.no_header =] 'header_value']
[,[@.width =] width]
[,[@.separator =] 'separator']
[,[@.echo_error =] 'echo_value']
[,[@.set_user =] 'user']
[,[@.dbuse =] 'database']

U Should be able to
[,[@.attachments =] 'attachments [;...n]']
easy enough

But to embed it as a BLOB into emails & not as an attachment is an interesting yet Scary Question

I Hope U are'nt a Spammer !!

lol

GW|||Why not use VB or ASP in this case to build the case and insert the messages in that form. You can blend sendmail with those programs too.