Sunday, March 11, 2012
How can I resolve concurrency problems in SQL Server 2005?
CREATE PROCEDURE add_ticket -- parameters DECLARE free_seats int BEGIN TRANSACTION SELECT free_seats = COUNT(*) FROM tickets WHERE seat_is_not_taken IF free_seats <> 0 INSERT INTO tickets VALUES(...) -- some other statements END TRANSACTION
The problem is that two processes can read the amount of free tickets concurrently and both save a ticket, even if there are no free seats left. I need a way to block processes from reading the amount of free tickets while other processes running the add_ticket procedure have not yet inserted a new ticket. SET TRANSACTION ISOLATION LEVEL does not help in this situation, am I right?
You are correct; a higher isolation level would not help ensure that multiple readers did not read the same rows simultaneously. However, there are several ways you could make this work. For instance, you could assign each seat a unique identifier (meaning, a unique key – not necessarily a GUID) and create a table for seats that have already been taken. Put a UNIQUE constraint on the table and you will be guaranteed that no seat is inserted twice.
That said, I think a more interesting option might be to employ SQL Service Broker. You could set up a conversation for each bus, and store the conversation handles in a table that can be referenced by readers before doing the RECEIVE. That way, the readers can filter appropriately. Drop a message into the queue for each seat on the bus. The readers can then simply RECEIVE the messages as needed (in the process, reserving seats on the bus). Service Broker will ensure that no message is received twice, meaning that you will no longer have any concurrency problems.PAE allows the OS to use more than 4GB of memory. AWE allows the
application to use more than 4GB.
--
Andrew J. Kelly SQL MVP
"rupart" <rupart@.discussions.microsoft.com> wrote in message
news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
> guys,
> what is the difference between AWE and PAE?|||for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
"Andrew J. Kelly" wrote:
> PAE allows the OS to use more than 4GB of memory. AWE allows the
> application to use more than 4GB.
> --
> Andrew J. Kelly SQL MVP
>
> "rupart" <rupart@.discussions.microsoft.com> wrote in message
> news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
> > guys,
> > what is the difference between AWE and PAE?
>
>|||AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI). If you
want SQL Server to utilize > 4GB memory, you need both settings.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"rupart" <rupart@.discussions.microsoft.com> wrote in message
news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com...
> for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
> "Andrew J. Kelly" wrote:
>> PAE allows the OS to use more than 4GB of memory. AWE allows the
>> application to use more than 4GB.
>> --
>> Andrew J. Kelly SQL MVP
>>
>> "rupart" <rupart@.discussions.microsoft.com> wrote in message
>> news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
>> > guys,
>> > what is the difference between AWE and PAE?
>>|||in that case...in a server with 5G of ram
should i put the /AWE /PAE swith in the same line in the boot.ini?
For the OS, i can see under system mgmt that 5G is enabled. How abt for sql?
how do i check it has 5G? Also, is there any significant on it? The
performance shd be better i suppose
Thank you
"Tibor Karaszi" wrote:
> AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI). If you
> want SQL Server to utilize > 4GB memory, you need both settings.
> --
> Tibor Karaszi, SQL Server MVP
> http://www.karaszi.com/sqlserver/default.asp
> http://www.solidqualitylearning.com/
>
> "rupart" <rupart@.discussions.microsoft.com> wrote in message
> news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com...
> > for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
> >
> > "Andrew J. Kelly" wrote:
> >
> >> PAE allows the OS to use more than 4GB of memory. AWE allows the
> >> application to use more than 4GB.
> >>
> >> --
> >> Andrew J. Kelly SQL MVP
> >>
> >>
> >> "rupart" <rupart@.discussions.microsoft.com> wrote in message
> >> news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
> >> > guys,
> >> > what is the difference between AWE and PAE?
> >>
> >>
> >>
>
>|||This is a multi-part message in MIME format.
--080301010603090003030909
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
boot.ini should have something like this:
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows Server 2003,
Enterprise" /fastdetect /pae /3gb
(The /3gb switch is not necessary, but for a box with 5gb of RAM it'll
provide a little more to the apps, i.e. SQL Server.)
To check the amount of physical RAM the OS is seeing you can just check
the Performance tab in task manager.
To turn on AWE memory for SQL Server you use the sp_configure stored
proc (in Query Analyzer for example):
exec sp_configure 'awe enabled', 1
reconfigure
go
Then you have to restart the SQL instance as the AWE setting only takes
affect on server startup. Also, when SQL Server is using AWE memory, it
cannot use dynamic memory management. It *will not swap pages out of
memory *if another app requests memory and the OS doesn't have enough to
satisfy the request (unlike the SQL dynamic memory manager). So you
should specify a "max server memory" amount with sp_configure. For
example, on your 5GB box, if you wanted to allocate 4GB to SQL and the
remaining 1GB to the OS & other apps, you would do this in QA:
exec sp_configure "max server memory", 5120
reconfigure
go
All this is documented in SQL BOL:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg.asp
To see how much memory SQL Server is currently consuming you can open
the System Monitor (perfmon.exe) and add the counter: SQLServer:Memory
Manager | Total Server Memory (KB). SQL BOL has a lot of good stuff on
AWE & memory management.
HTH
--
*mike hodgson*
/ mallesons stephen jaques/
blog: http://sqlnerd.blogspot.com
rupart wrote:
>in that case...in a server with 5G of ram
>should i put the /AWE /PAE swith in the same line in the boot.ini?
>For the OS, i can see under system mgmt that 5G is enabled. How abt for sql?
>how do i check it has 5G? Also, is there any significant on it? The
>performance shd be better i suppose
>Thank you
>"Tibor Karaszi" wrote:
>
>>AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI). If you
>>want SQL Server to utilize > 4GB memory, you need both settings.
>>--
>>Tibor Karaszi, SQL Server MVP
>>http://www.karaszi.com/sqlserver/default.asp
>>http://www.solidqualitylearning.com/
>>
>>"rupart" <rupart@.discussions.microsoft.com> wrote in message
>>news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com...
>>
>>for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
>>"Andrew J. Kelly" wrote:
>>
>>PAE allows the OS to use more than 4GB of memory. AWE allows the
>>application to use more than 4GB.
>>--
>>Andrew J. Kelly SQL MVP
>>
>>"rupart" <rupart@.discussions.microsoft.com> wrote in message
>>news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
>>
>>guys,
>>what is the difference between AWE and PAE?
>>
>>
>>
>>
--080301010603090003030909
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<tt>boot.ini should have something like this:<br>
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows Server 2003,
Enterprise" /fastdetect /pae /3gb<br>
<br>
(The /3gb switch is not necessary, but for a box with 5gb of RAM it'll
provide a little more to the apps, i.e. SQL Server.)<br>
<br>
To check the amount of physical RAM the OS is seeing you can just check
the Performance tab in task manager.<br>
<br>
To turn on AWE memory for SQL Server you use the sp_configure stored
proc (in Query Analyzer for example):<br>
</tt>
<blockquote><tt>exec sp_configure 'awe enabled', 1</tt><br>
<tt>reconfigure</tt><br>
<tt>go<br>
</tt></blockquote>
<tt>Then you have to restart the SQL instance as the AWE setting only
takes affect on server startup. Also, when SQL Server is using AWE
memory, it cannot use dynamic memory management. It <b>will not swap
pages out of memory </b>if another app requests memory and the OS
doesn't have enough to satisfy the request (unlike the SQL dynamic
memory manager). So you should specify a "max server memory" amount
with sp_configure. For example, on your 5GB box, if you wanted to
allocate 4GB to SQL and the remaining 1GB to the OS & other apps,
you would do this in QA:<br>
</tt>
<blockquote><tt>exec sp_configure "max server memory", 5120</tt><br>
<tt>reconfigure</tt><br>
<tt>go</tt><br>
</blockquote>
<tt>All this is documented in SQL BOL:<br>
<a class="moz-txt-link-freetext" href="http://links.10026.com/?link=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg..asp</a><br>">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg..asp</a><br>
<br>
To see how much memory SQL Server is currently consuming you can open
the System Monitor (perfmon.exe) and add the counter: SQLServer:Memory
Manager | Total Server Memory (KB). SQL BOL has a lot of good stuff on
AWE & memory management.<br>
<br>
HTH<br>
</tt>
<div class="moz-signature">
<title></title>
<meta http-equiv="Content-Type" content="text/html; ">
<p><span lang="en-au"><font face="Tahoma" size="2">--<br>
</font> </span><b><span lang="en-au"><font face="Tahoma" size="2">mike
hodgson</font></span></b><span lang="en-au"><br>
<em><font face="Tahoma" size="2"> mallesons</font><font face="Tahoma"> </font><font
face="Tahoma" size="2">stephen</font><font face="Tahoma"> </font><font
face="Tahoma" size="2"> jaques</font></em><font face="Tahoma"><br>
</font><font face="Tahoma" size="2">blog:</font><font face="Tahoma"
size="2"> <a href="http://links.10026.com/?link=/">http://sqlnerd.blogspot.com">
http://sqlnerd.blogspot.com</a></font></span> </p>
</div>
<br>
<br>
rupart wrote:
<blockquote cite="mid0C68F97D-764B-4C1A-926D-3926F39CC830@.microsoft.com"
type="cite">
<pre wrap="">in that case...in a server with 5G of ram
should i put the /AWE /PAE swith in the same line in the boot.ini?
For the OS, i can see under system mgmt that 5G is enabled. How abt for sql?
how do i check it has 5G? Also, is there any significant on it? The
performance shd be better i suppose
Thank you
"Tibor Karaszi" wrote:
</pre>
<blockquote type="cite">
<pre wrap="">AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI). If you
want SQL Server to utilize > 4GB memory, you need both settings.
--
Tibor Karaszi, SQL Server MVP
<a class="moz-txt-link-freetext" href="http://links.10026.com/?link=http://www.karaszi.com/sqlserver/default.asp</a>">http://www.karaszi.com/sqlserver/default.asp">http://www.karaszi.com/sqlserver/default.asp</a>
<a class="moz-txt-link-freetext" href="http://links.10026.com/?link=http://www.solidqualitylearning.com/</a>">http://www.solidqualitylearning.com/">http://www.solidqualitylearning.com/</a>
"rupart" <a class="moz-txt-link-rfc2396E" href="http://links.10026.com/?link=mailto:rupart@.discussions.microsoft.com"><rupart@.discussions.microsoft.com></a> wrote in message
<a class="moz-txt-link-freetext" href="http://links.10026.com/?link=news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com">news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com</a>...
</pre>
<blockquote type="cite">
<pre wrap="">for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
"Andrew J. Kelly" wrote:
</pre>
<blockquote type="cite">
<pre wrap="">PAE allows the OS to use more than 4GB of memory. AWE allows the
application to use more than 4GB.
--
Andrew J. Kelly SQL MVP
"rupart" <a class="moz-txt-link-rfc2396E" href="http://links.10026.com/?link=mailto:rupart@.discussions.microsoft.com"><rupart@.discussions.microsoft.com></a> wrote in message
<a class="moz-txt-link-freetext" href="http://links.10026.com/?link=news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com">news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com</a>...
</pre>
<blockquote type="cite">
<pre wrap="">guys,
what is the difference between AWE and PAE?
</pre>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
</blockquote>
</body>
</html>
--080301010603090003030909--|||does /3g means the system will allocate 3g for system and the rest for
sql(that is after enabling thru AWE, rite?)?
yeah, good link...thank you
"Mike Hodgson" wrote:
> boot.ini should have something like this:
> multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows Server 2003,
> Enterprise" /fastdetect /pae /3gb
> (The /3gb switch is not necessary, but for a box with 5gb of RAM it'll
> provide a little more to the apps, i.e. SQL Server.)
> To check the amount of physical RAM the OS is seeing you can just check
> the Performance tab in task manager.
> To turn on AWE memory for SQL Server you use the sp_configure stored
> proc (in Query Analyzer for example):
> exec sp_configure 'awe enabled', 1
> reconfigure
> go
> Then you have to restart the SQL instance as the AWE setting only takes
> affect on server startup. Also, when SQL Server is using AWE memory, it
> cannot use dynamic memory management. It *will not swap pages out of
> memory *if another app requests memory and the OS doesn't have enough to
> satisfy the request (unlike the SQL dynamic memory manager). So you
> should specify a "max server memory" amount with sp_configure. For
> example, on your 5GB box, if you wanted to allocate 4GB to SQL and the
> remaining 1GB to the OS & other apps, you would do this in QA:
> exec sp_configure "max server memory", 5120
> reconfigure
> go
> All this is documented in SQL BOL:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg.asp
> To see how much memory SQL Server is currently consuming you can open
> the System Monitor (perfmon.exe) and add the counter: SQLServer:Memory
> Manager | Total Server Memory (KB). SQL BOL has a lot of good stuff on
> AWE & memory management.
> HTH
> --
> *mike hodgson*
> / mallesons stephen jaques/
> blog: http://sqlnerd.blogspot.com
>
> rupart wrote:
> >in that case...in a server with 5G of ram
> >should i put the /AWE /PAE swith in the same line in the boot.ini?
> >For the OS, i can see under system mgmt that 5G is enabled. How abt for sql?
> >how do i check it has 5G? Also, is there any significant on it? The
> >performance shd be better i suppose
> >Thank you
> >
> >"Tibor Karaszi" wrote:
> >
> >
> >
> >>AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI). If you
> >>want SQL Server to utilize > 4GB memory, you need both settings.
> >>
> >>--
> >>Tibor Karaszi, SQL Server MVP
> >>http://www.karaszi.com/sqlserver/default.asp
> >>http://www.solidqualitylearning.com/
> >>
> >>
> >>"rupart" <rupart@.discussions.microsoft.com> wrote in message
> >>news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com...
> >>
> >>
> >>for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
> >>
> >>"Andrew J. Kelly" wrote:
> >>
> >>
> >>
> >>PAE allows the OS to use more than 4GB of memory. AWE allows the
> >>application to use more than 4GB.
> >>
> >>--
> >>Andrew J. Kelly SQL MVP
> >>
> >>
> >>"rupart" <rupart@.discussions.microsoft.com> wrote in message
> >>news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
> >>
> >>
> >>guys,
> >>what is the difference between AWE and PAE?
> >>
> >>
> >>
> >>
> >>
> >>
> >>
> >>
>|||The other way around. 3 GB for the application and 1 GB for the system.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"rupart" <rupart@.discussions.microsoft.com> wrote in message
news:4944B057-1DC7-4638-BB88-9040FDCC9B9F@.microsoft.com...
> does /3g means the system will allocate 3g for system and the rest for
> sql(that is after enabling thru AWE, rite?)?
> yeah, good link...thank you
> "Mike Hodgson" wrote:
>> boot.ini should have something like this:
>> multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows Server 2003,
>> Enterprise" /fastdetect /pae /3gb
>> (The /3gb switch is not necessary, but for a box with 5gb of RAM it'll
>> provide a little more to the apps, i.e. SQL Server.)
>> To check the amount of physical RAM the OS is seeing you can just check
>> the Performance tab in task manager.
>> To turn on AWE memory for SQL Server you use the sp_configure stored
>> proc (in Query Analyzer for example):
>> exec sp_configure 'awe enabled', 1
>> reconfigure
>> go
>> Then you have to restart the SQL instance as the AWE setting only takes
>> affect on server startup. Also, when SQL Server is using AWE memory, it
>> cannot use dynamic memory management. It *will not swap pages out of
>> memory *if another app requests memory and the OS doesn't have enough to
>> satisfy the request (unlike the SQL dynamic memory manager). So you
>> should specify a "max server memory" amount with sp_configure. For
>> example, on your 5GB box, if you wanted to allocate 4GB to SQL and the
>> remaining 1GB to the OS & other apps, you would do this in QA:
>> exec sp_configure "max server memory", 5120
>> reconfigure
>> go
>> All this is documented in SQL BOL:
>> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg.asp
>> To see how much memory SQL Server is currently consuming you can open
>> the System Monitor (perfmon.exe) and add the counter: SQLServer:Memory
>> Manager | Total Server Memory (KB). SQL BOL has a lot of good stuff on
>> AWE & memory management.
>> HTH
>> --
>> *mike hodgson*
>> / mallesons stephen jaques/
>> blog: http://sqlnerd.blogspot.com
>>
>> rupart wrote:
>> >in that case...in a server with 5G of ram
>> >should i put the /AWE /PAE swith in the same line in the boot.ini?
>> >For the OS, i can see under system mgmt that 5G is enabled. How abt for sql?
>> >how do i check it has 5G? Also, is there any significant on it? The
>> >performance shd be better i suppose
>> >Thank you
>> >
>> >"Tibor Karaszi" wrote:
>> >
>> >
>> >
>> >>AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI).
>> >>If you
>> >>want SQL Server to utilize > 4GB memory, you need both settings.
>> >>
>> >>--
>> >>Tibor Karaszi, SQL Server MVP
>> >>http://www.karaszi.com/sqlserver/default.asp
>> >>http://www.solidqualitylearning.com/
>> >>
>> >>
>> >>"rupart" <rupart@.discussions.microsoft.com> wrote in message
>> >>news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com...
>> >>
>> >>
>> >>for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
>> >>
>> >>"Andrew J. Kelly" wrote:
>> >>
>> >>
>> >>
>> >>PAE allows the OS to use more than 4GB of memory. AWE allows the
>> >>application to use more than 4GB.
>> >>
>> >>--
>> >>Andrew J. Kelly SQL MVP
>> >>
>> >>
>> >>"rupart" <rupart@.discussions.microsoft.com> wrote in message
>> >>news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
>> >>
>> >>
>> >>guys,
>> >>what is the difference between AWE and PAE?
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>
>> >>|||This is a multi-part message in MIME format.
--010506000107000909000008
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Oops - slight typo in my "max server memory" statement. To set a max
server memory of 4GB you would run:
exec sp_configure "max server memory", 4096
reconfigure
go
The 5120 figure I included in my previous post would try to set it at
5GB (not 4GB).
--
*mike hodgson*
blog: http://sqlnerd.blogspot.com
Mike Hodgson wrote:
> boot.ini should have something like this:
> multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows Server 2003,
> Enterprise" /fastdetect /pae /3gb
> (The /3gb switch is not necessary, but for a box with 5gb of RAM it'll
> provide a little more to the apps, i.e. SQL Server.)
> To check the amount of physical RAM the OS is seeing you can just
> check the Performance tab in task manager.
> To turn on AWE memory for SQL Server you use the sp_configure stored
> proc (in Query Analyzer for example):
> exec sp_configure 'awe enabled', 1
> reconfigure
> go
> Then you have to restart the SQL instance as the AWE setting only
> takes affect on server startup. Also, when SQL Server is using AWE
> memory, it cannot use dynamic memory management. It *will not swap
> pages out of memory *if another app requests memory and the OS doesn't
> have enough to satisfy the request (unlike the SQL dynamic memory
> manager). So you should specify a "max server memory" amount with
> sp_configure. For example, on your 5GB box, if you wanted to allocate
> 4GB to SQL and the remaining 1GB to the OS & other apps, you would do
> this in QA:
> exec sp_configure "max server memory", 5120
> reconfigure
> go
> All this is documented in SQL BOL:
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg..asp
> To see how much memory SQL Server is currently consuming you can open
> the System Monitor (perfmon.exe) and add the counter: SQLServer:Memory
> Manager | Total Server Memory (KB). SQL BOL has a lot of good stuff
> on AWE & memory management.
> HTH
> --
> *mike hodgson*
> / mallesons stephen jaques/
> blog: http://sqlnerd.blogspot.com
>
> rupart wrote:
>>in that case...in a server with 5G of ram
>>should i put the /AWE /PAE swith in the same line in the boot.ini?
>>For the OS, i can see under system mgmt that 5G is enabled. How abt for sql?
>>how do i check it has 5G? Also, is there any significant on it? The
>>performance shd be better i suppose
>>Thank you
>>"Tibor Karaszi" wrote:
>>
>>AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI). If you
>>want SQL Server to utilize > 4GB memory, you need both settings.
>>--
>>Tibor Karaszi, SQL Server MVP
>>http://www.karaszi.com/sqlserver/default.asp
>>http://www.solidqualitylearning.com/
>>
>>"rupart" <rupart@.discussions.microsoft.com> wrote in message
>>news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com...
>>
>>for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
>>"Andrew J. Kelly" wrote:
>>
>>PAE allows the OS to use more than 4GB of memory. AWE allows the
>>application to use more than 4GB.
>>--
>>Andrew J. Kelly SQL MVP
>>
>>"rupart" <rupart@.discussions.microsoft.com> wrote in message
>>news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com...
>>
>>guys,
>>what is the difference between AWE and PAE?
>>
>>
>>
--010506000107000909000008
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
<tt>Oops - slight typo in my "max server memory" statement. To set a
max server memory of 4GB you would run:<br>
</tt>
<blockquote><tt>exec sp_configure "max server memory", 4096</tt><br>
<tt>reconfigure</tt><br>
<tt>go</tt><br>
</blockquote>
<tt>The 5120 figure I included in my previous post would try to set it
at 5GB (not 4GB).<br>
</tt>
<div class="moz-signature">
<title></title>
<meta http-equiv="Content-Type" content="text/html; ">
<p><span lang="en-au"><font face="Tahoma" size="2">--<br>
</font></span> <b><span lang="en-au"><font face="Tahoma" size="2">mike
hodgson</font></span></b><span lang="en-au"><br>
<font face="Tahoma" size="2">blog:</font><font face="Tahoma" size="2"> <a
href="http://links.10026.com/?link=http://sqlnerd.blogspot.com</a></font></span>">http://sqlnerd.blogspot.com">http://sqlnerd.blogspot.com</a></font></span>
</p>
</div>
<br>
<br>
Mike Hodgson wrote:
<blockquote cite="midOSFjFxFfFHA.3944@.tk2msftngp13.phx.gbl" type="cite">
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
<tt>boot.ini should have something like this:<br>
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Windows Server 2003,
Enterprise" /fastdetect /pae /3gb<br>
<br>
(The /3gb switch is not necessary, but for a box with 5gb of RAM it'll
provide a little more to the apps, i.e. SQL Server.)<br>
<br>
To check the amount of physical RAM the OS is seeing you can just check
the Performance tab in task manager.<br>
<br>
To turn on AWE memory for SQL Server you use the sp_configure stored
proc (in Query Analyzer for example):<br>
</tt>
<blockquote><tt>exec sp_configure 'awe enabled', 1</tt><br>
<tt>reconfigure</tt><br>
<tt>go<br>
</tt></blockquote>
<tt>Then you have to restart the SQL instance as the AWE setting only
takes affect on server startup. Also, when SQL Server is using AWE
memory, it cannot use dynamic memory management. It <b>will not swap
pages out of memory </b>if another app requests memory and the OS
doesn't have enough to satisfy the request (unlike the SQL dynamic
memory manager). So you should specify a "max server memory" amount
with sp_configure. For example, on your 5GB box, if you wanted to
allocate 4GB to SQL and the remaining 1GB to the OS & other apps,
you would do this in QA:<br>
</tt>
<blockquote><tt>exec sp_configure "max server memory", 5120</tt><br>
<tt>reconfigure</tt><br>
<tt>go</tt><br>
</blockquote>
<tt>All this is documented in SQL BOL:<br>
<a class="moz-txt-link-freetext"
href="http://links.10026.com/?link=http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg..asp</a><br>">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adminsql/ad_config_3stg..asp</a><br>
<br>
To see how much memory SQL Server is currently consuming you can open
the System Monitor (perfmon.exe) and add the counter: SQLServer:Memory
Manager | Total Server Memory (KB). SQL BOL has a lot of good stuff on
AWE & memory management.<br>
<br>
HTH<br>
</tt>
<div class="moz-signature">
<title></title>
<meta http-equiv="Content-Type" content="text/html; ">
<p><span lang="en-au"><font face="Tahoma" size="2">--<br>
</font> </span><b><span lang="en-au"><font face="Tahoma" size="2">mike
hodgson</font></span></b><span lang="en-au"><br>
<em><font face="Tahoma" size="2"> mallesons</font><font face="Tahoma">
</font><font face="Tahoma" size="2">stephen</font><font face="Tahoma">
</font><font face="Tahoma" size="2"> jaques</font></em><font
face="Tahoma"><br>
</font><font face="Tahoma" size="2">blog:</font><font face="Tahoma"
size="2"> <a href="http://links.10026.com/?link=/">http://sqlnerd.blogspot.com">
http://sqlnerd.blogspot.com</a></font></span> </p>
</div>
<br>
<br>
rupart wrote:
<blockquote
cite="mid0C68F97D-764B-4C1A-926D-3926F39CC830@.microsoft.com"
type="cite">
<pre wrap="">in that case...in a server with 5G of ram
should i put the /AWE /PAE swith in the same line in the boot.ini?
For the OS, i can see under system mgmt that 5G is enabled. How abt for sql?
how do i check it has 5G? Also, is there any significant on it? The
performance shd be better i suppose
Thank you
"Tibor Karaszi" wrote:
</pre>
<blockquote type="cite">
<pre wrap="">AWE is a SQL Server setting (sp_configure) and PAE is an operating system setting (BOOT.INI). If you
want SQL Server to utilize > 4GB memory, you need both settings.
--
Tibor Karaszi, SQL Server MVP
<a class="moz-txt-link-freetext"
href="http://links.10026.com/?link=http://www.karaszi.com/sqlserver/default.asp</a>">http://www.karaszi.com/sqlserver/default.asp">http://www.karaszi.com/sqlserver/default.asp</a>
<a class="moz-txt-link-freetext"
href="http://links.10026.com/?link=http://www.solidqualitylearning.com/</a>">http://www.solidqualitylearning.com/">http://www.solidqualitylearning.com/</a>
"rupart" <a class="moz-txt-link-rfc2396E"
href="http://links.10026.com/?link=mailto:rupart@.discussions.microsoft.com"><rupart@.discussions.microsoft.com></a> wrote in message
<a class="moz-txt-link-freetext"
href="http://links.10026.com/?link=news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com">news:82A723DF-8EEA-431B-8669-79146E1DCA1D@.microsoft.com</a>...
</pre>
<blockquote type="cite">
<pre wrap="">for SQL server, shd i enable PAE or AWE? Can both be enabled at the same time?
"Andrew J. Kelly" wrote:
</pre>
<blockquote type="cite">
<pre wrap="">PAE allows the OS to use more than 4GB of memory. AWE allows the
application to use more than 4GB.
--
Andrew J. Kelly SQL MVP
"rupart" <a class="moz-txt-link-rfc2396E"
href="http://links.10026.com/?link=mailto:rupart@.discussions.microsoft.com"><rupart@.discussions.microsoft.com></a> wrote in message
<a class="moz-txt-link-freetext"
href="http://links.10026.com/?link=news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com">news:7D318157-43B8-49AD-9DF7-F38F6ABEEA03@.microsoft.com</a>...
</pre>
<blockquote type="cite">
<pre wrap="">guys,
what is the difference between AWE and PAE?
</pre>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
</blockquote>
<pre wrap="">
</pre>
</blockquote>
</blockquote>
</blockquote>
</body>
</html>
--010506000107000909000008--
Friday, February 24, 2012
Avoid Inserting Duplicate Entries
I am somewhat new to sql server. So help me in whatever way you can.
I have two tables one of which doesnt have a primary key(table A) and other has a composite key formed of two columns(table B). I need to insert entries in table B from table A(table A has a unique constratint UID which is passed to table B). Table B also has a unique ID which is different from UID of table A.
Sometimes table A tries to insert a duplicate entry which is denied by table B since it has a primary key.
The insert query is as below.
table A - CORE
table B - CRF
INSERT INTO CRF (CORE_UID,ACCT_NUM_MIN, ACCT_NUM_MAX,BIN, BUS_ID,BUS_NM,ISO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE)
(SELECT UID,LEFT(ACCT_NUM_MIN,16),LEFT( ACCT_NUM_MAX,16),BIN, BUS_ID,BUS_NM,ISO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE FROM CORE WHERE UID NOT IN (SELECT CORE_UID FROM CRF))
I am not worried about the performance. I have tried if not exists and except but since i am new i am not able to figure out the problem.
Thank you in advance for all who try to help me out.
Quote:
Originally Posted by desirocks
Hi all,
I am somewhat new to sql server. So help me in whatever way you can.
I have two tables one of which doesnt have a primary key(table A) and other has a composite key formed of two columns(table B). I need to insert entries in table B from table A(table A has a unique constratint UID which is passed to table B). Table B also has a unique ID which is different from UID of table A.
Sometimes table A tries to insert a duplicate entry which is denied by table B since it has a primary key.
The insert query is as below.
table A - CORE
table B - CRF
INSERT INTO CRF (CORE_UID,ACCT_NUM_MIN, ACCT_NUM_MAX,BIN, BUS_ID,BUS_NM,ISO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE)
(SELECT UID,LEFT(ACCT_NUM_MIN,16),LEFT( ACCT_NUM_MAX,16),BIN, BUS_ID,BUS_NM,ISO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE FROM CORE WHERE UID NOT IN (SELECT CORE_UID FROM CRF))
I am not worried about the performance. I have tried if not exists and except but since i am new i am not able to figure out the problem.
Thank you in advance for all who try to help me out.
i believe CONSTRAINT are still the best way to enforce your data integrity. you can also do this through trigger or check the table before insert, but i believe it'll be slower.|||
Quote:
Originally Posted by ck9663
i believe CONSTRAINT are still the best way to enforce your data integrity. you can also do this through trigger or check the table before insert, but i believe it'll be slower.
I AM NOT CONCERNED WITH THE PERFORMANCE... CAN YOU HELP ME WRITE THIS TRIGGER OR PROVIDE SYNTAX TO CHECK THE TABLE BEFORE THE INSERT?|||
Quote:
Originally Posted by desirocks
Hi all,
I am somewhat new to sql server. So help me in whatever way you can.
I have two tables one of which doesnt have a primary key(table A) and other has a composite key formed of two columns(table B). I need to insert entries in table B from table A(table A has a unique constratint UID which is passed to table B). Table B also has a unique ID which is different from UID of table A.
Sometimes table A tries to insert a duplicate entry which is denied by table B since it has a primary key.
The insert query is as below.
table A - CORE
table B - CRF
INSERT INTO CRF (CORE_UID,ACCT_NUM_MIN, ACCT_NUM_MAX,BIN, BUS_ID,BUS_NM,ISO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE)
(SELECT UID,LEFT(ACCT_NUM_MIN,16),LEFT( ACCT_NUM_MAX,16),BIN, BUS_ID,BUS_NM,ISO_CTRY_CD, REGN_CD, PROD_TYPE_CD, CARD_TYPE FROM CORE WHERE UID NOT IN (SELECT CORE_UID FROM CRF))
I am not worried about the performance. I have tried if not exists and except but since i am new i am not able to figure out the problem.
Thank you in advance for all who try to help me out.
Your above INSERT QUERY should work fine. What is the problem that you are facing here??|||
Quote:
Originally Posted by amitpatel66
Your above INSERT QUERY should work fine. What is the problem that you are facing here??
Since table CRF does have a composite key it doesnt allow duplicate entries and hence my application gives me an error. I want to some how check if the entry already exists or not and based upon the same i need to insert. Is there some way i can change the query ?|||It would help to know what column(s) comprise your primary key on table B. You say that A nad B have different unique columns, but your insert statement only limits duplicates based on table A's unique key. If table B has a different unique key then that is what you need to check fo in your not in statement. Also, a NOT EXISTS should be faster, but first you need to figure out what is unique on table B.|||OK, since you have said B has a composite key then you need something like this (I assumed that CORE_UID, BIN was the composite key, so adjust as needed):
INSERT INTO CRF (CORE_UID,
ACCT_NUM_MIN,
ACCT_NUM_MAX,
BIN,
BUS_ID,
BUS_NM,
ISO_CTRY_CD,
REGN_CD,
PROD_TYPE_CD,
CARD_TYPE)
SELECT UID,
LEFT(ACCT_NUM_MIN,16),
LEFT(ACCT_NUM_MAX,16),
BIN,
BUS_ID,
BUS_NM,
ISO_CTRY_CD,
REGN_CD,
PROD_TYPE_CD,
CARD_TYPE
FROM CORE A
WHERE NOT EXISTS (SELECT 1 FROM CRF B WHERE B.CORE_UID = A.UID and B.BIN = A.BIN)|||
Quote:
Originally Posted by rob313
OK, since you have said B has a composite key then you need something like this (I assumed that CORE_UID, BIN was the composite key, so adjust as needed):
INSERT INTO CRF (CORE_UID,
ACCT_NUM_MIN,
ACCT_NUM_MAX,
BIN,
BUS_ID,
BUS_NM,
ISO_CTRY_CD,
REGN_CD,
PROD_TYPE_CD,
CARD_TYPE)
SELECT UID,
LEFT(ACCT_NUM_MIN,16),
LEFT(ACCT_NUM_MAX,16),
BIN,
BUS_ID,
BUS_NM,
ISO_CTRY_CD,
REGN_CD,
PROD_TYPE_CD,
CARD_TYPE
FROM CORE A
WHERE NOT EXISTS (SELECT 1 FROM CRF B WHERE B.CORE_UID = A.UID and B.BIN = A.BIN)
hi rob,
The composite key comprises of ACCT_NUM_MIN and ACCT_NUM_MAX. The UID of CORE is being transferred to CRF and CRF also has its own UID. Can you specify what whould be the change in the query now?|||In that case, this should work:
INSERT INTO CRF (CORE_UID,
ACCT_NUM_MIN,
ACCT_NUM_MAX,
BIN,
BUS_ID,
BUS_NM,
ISO_CTRY_CD,
REGN_CD,
PROD_TYPE_CD,
CARD_TYPE)
SELECT UID,
LEFT(ACCT_NUM_MIN,16),
LEFT(ACCT_NUM_MAX,16),
BIN,
BUS_ID,
BUS_NM,
ISO_CTRY_CD,
REGN_CD,
PROD_TYPE_CD,
CARD_TYPE
FROM CORE A
WHERE NOT EXISTS (SELECT 1 FROM CRF B WHERE B.ACCT_NUM_MIN = A.LEFT(ACCT_NUM_MIN,16) and B.ACCT_NUM_MAX = A.LEFT(ACCT_NUM_MAX,16))
Avoid duplicate primary key error
How can I avoid duplicate primary key error when I use DetailsView Inserting that the field column is one of the primary key ?
Thanks in advance !
stephen
Before insertin the new row, you can check the table to see whether there is a row in the table with the same key value as the new row. For example:
if exists (select * from Orders where OrderID=@.newOrderID)
//not insert
else //insert
|||Can you show me the detail of correct syntax ? I'm very new in ASP.NET 2.0. I did type the statement in the ??.aspx.cs and syntax error found.
stephen
|||Sorry I forgot to say: the code in my last post is T-SQL statements, so you can use them in SqlCommand or something else.
Friday, February 10, 2012
Autonumber when inserting
I have three tables last_id, customer, prospect. The "last_id" table have
one colum that stores the last used id number (int), customer tables stores
info about the customer and a "last_id" number and the prospect stores new
customers!
I want to make an insert into customer table from the prospect table and ad
one extra column with the last_id number +1
insert into customer(name,adress,l_id)
select p_name,p_adress,l_id
from prospect,last_id
i don′t want alter the table and use identity
i can make i work with a cursor, is there any other way to do it'Hi
CREATE TABLE #Test
(
col INT
)
INSERT INTO #Test VALUES (1)
GO
INSERT INTO #Test SELECT COALESCE(MAX(col),0)+1 FROM #Test
GO
SELECT * FROM #test
DROP TABLE #Test
"LeSurfer" <LeSurfer@.discussions.microsoft.com> wrote in message
news:8C74D3BF-12D2-4FED-B07D-5070867310B4@.microsoft.com...
> Hi i have a problem that i cant solve!
> I have three tables last_id, customer, prospect. The "last_id" table have
> one colum that stores the last used id number (int), customer tables
stores
> info about the customer and a "last_id" number and the prospect stores new
> customers!
> I want to make an insert into customer table from the prospect table and
ad
> one extra column with the last_id number +1
> insert into customer(name,adress,l_id)
> select p_name,p_adress,l_id
> from prospect,last_id
> i dont want alter the table and use identity
> i can make i work with a cursor, is there any other way to do it'
>|||I couldn′t make it work, i tried this
select coalesce(max(l_id),0)+1,name
from ct_contact cross join kundfil
this is the error message:
Server: Msg 8118, Level 16, State 1, Line 1
Column 'Kundfil.kund' is invalid in the select list because it is not
contained in an aggregate function and there is no GROUP BY clause.
any ideas on what i could try'
"Uri Dimant" wrote:
> Hi
> CREATE TABLE #Test
> (
> col INT
> )
> INSERT INTO #Test VALUES (1)
> GO
> INSERT INTO #Test SELECT COALESCE(MAX(col),0)+1 FROM #Test
> GO
> SELECT * FROM #test
> DROP TABLE #Test
>
> "LeSurfer" <LeSurfer@.discussions.microsoft.com> wrote in message
> news:8C74D3BF-12D2-4FED-B07D-5070867310B4@.microsoft.com...
> stores
> ad
>
>|||Hi
Add this column 'Kundfil.kund' into GROUP BY clause
"LeSurfer" <LeSurfer@.discussions.microsoft.com> wrote in message
news:D5A79FA4-6E93-4EB7-870D-F754B26DF287@.microsoft.com...
> I couldnt make it work, i tried this
> select coalesce(max(l_id),0)+1,name
> from ct_contact cross join kundfil
> this is the error message:
> Server: Msg 8118, Level 16, State 1, Line 1
> Column 'Kundfil.kund' is invalid in the select list because it is not
> contained in an aggregate function and there is no GROUP BY clause.
> any ideas on what i could try'
> "Uri Dimant" wrote:
>
have
new
and