To be able to insert a record into a table with a "hardcoded" ID you simply run:
SET IDENTITY_INSERT mytable ON
--run your insert code here
SET IDENTITY_INSERT mytable OFF
Tuesday, December 22, 2009
Tuesday, December 1, 2009
Reseed All Identity Columns in SQL Server 2005
EXEC sp_msforeachtable @command1 = 'DBCC CHECKIDENT (''?'', RESEED)'
This will get the highest record ID for each table and reset the identity seed to one number higher.
It will display any error for any table that does not have an identity column.
To do only one table you can run this:
DBCC CHECKIDENT ('tablename', RESEED)
To see what the current seed is:
DBCC CHECKIDENT ('tablename', NORESEED)
This will get the highest record ID for each table and reset the identity seed to one number higher.
It will display any error for any table that does not have an identity column.
To do only one table you can run this:
DBCC CHECKIDENT ('tablename', RESEED)
To see what the current seed is:
DBCC CHECKIDENT ('tablename', NORESEED)
Tuesday, October 27, 2009
PeerGuardian Replacement PeerBlock
PeerBlock appears to be the exact same program as PeerGuardian except it installs on all windows system including 64bit w/o having to hassle with it.
http://www.peerblock.com/
http://www.peerblock.com/
Monday, August 31, 2009
Peer Guardian 2 64bit Installation Instructions
UPDATE: Use PeerBlock instead.
--------------------------------------------------------------
Download Driver Signature Enforcement Overrider and follow the directions.
But basically you run the program.
Select Enable Test Mode -> click next
Select Sign a System File -> click next
then put in your_peerguardian_directory/pgfilter.sys and hit ok.
--------------------------------------------------------------
Download Driver Signature Enforcement Overrider and follow the directions.
But basically you run the program.
Select Enable Test Mode -> click next
Select Sign a System File -> click next
then put in your_peerguardian_directory/pgfilter.sys and hit ok.
Daemon Tools Windows 7 Upgrade Issue
You might find after upgrading to windows 7 that daemon tools (also alcohol 120%) won't run and is impossible to uninstall or reinstall.
To avoid this problem all together make sure and uninstall daemon tools before upgrading to windows 7.
If you didn't do that simply follow these steps:
To avoid this problem all together make sure and uninstall daemon tools before upgrading to windows 7.
If you didn't do that simply follow these steps:
- delete your daemon tools folder
- using regedit delete the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\sptd
directory. If it won't let you delete it, right click on the directory click the 'Full Control' checkbox then advanced and check the subfolder check box and 'ok' your way out. Then try and delete it. - Go into your windows installation folder/system32/drivers and delete sptd.sys
- Reboot your PC
- Now you should be able to install Daemon Tools
Friday, August 28, 2009
SQLServer 2005 Generate Scripts Append Bug
There is a known bug in SQL Management Studio 2005 where when you try to generate scripts and you set 'Include Descriptive Headers' to false, then 'Append to File' will always be true.
Sadly they fixed this in SMS 2008, but didn't include the fix in SP3 for SMS2005.
The only work around I've found is to download SQLServer 2008 and use SQL Management Studio 2008. The downside to this is that the scripts 2008 generates differ from what 2005 generates.
https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=387334
Sadly they fixed this in SMS 2008, but didn't include the fix in SP3 for SMS2005.
The only work around I've found is to download SQLServer 2008 and use SQL Management Studio 2008. The downside to this is that the scripts 2008 generates differ from what 2005 generates.
https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=387334
Thursday, August 13, 2009
Select Into Multiple Variables
DECLARE @x nvarchar(max)
DECLARE @y nvarchar(max)
select @x=name,@y=city FROM (SELECT TOP 1 name, city FROM Table1) a
SELECT @x, @y
DECLARE @y nvarchar(max)
select @x=name,@y=city FROM (SELECT TOP 1 name, city FROM Table1) a
SELECT @x, @y
Wednesday, April 8, 2009
Visual Studio 2008: How to add a command line argument in debug mode
Right click on your project -> choose properties -> Debug tab
under 'Start Options' there should be a text box called 'Command line arguments'
Now just type your arguments there like you would at the command line.
example:
command line: program.exe my_argument my_2nd_argument
in the box you would just type: my_argument my_2nd_argument
under 'Start Options' there should be a text box called 'Command line arguments'
Now just type your arguments there like you would at the command line.
example:
command line: program.exe my_argument my_2nd_argument
in the box you would just type: my_argument my_2nd_argument
Wednesday, April 1, 2009
SQL: 24hr Pivot
this is a little sample of how to pivot data in the form of
names|values|hours
a|1|12
a|9.1|13
b|2.5|12
b|3.6|13
and change it to:
names|12|13
a|1|9.1
b|2.5|3.6
SELECT * FROM (
SELECT names,Hours, Values
FROM aTable a
WHERE a.names IN ('a','b')
) p
SUM(values) FOR [hours] IN ([0],[1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23])
) AS pvt
Friday, March 20, 2009
SQL: Randomly Select One Record from Multiple Categories
This query will randomly select one record from multiple categories that you specify. First the inner select partitions the record set based on a specific field, then order's it randomly by using newid(). The outer select then selects the top row from each category (aka the partioned group). The top record is always random due ordering by newid().
SELECT * FROM (
SELECT
ROW_NUMBER() OVER(PARTITION BY a.Category ORDER BY newid()) AS RowNumber,
*
FROM Table a ) b
WHERE RowNumber = 1
SELECT * FROM (
SELECT
ROW_NUMBER() OVER(PARTITION BY a.Category ORDER BY newid()) AS RowNumber,
*
FROM Table a ) b
WHERE RowNumber = 1
Thursday, March 5, 2009
SQL: More Fun with Unpivot
takes a table like:
date 0 1 2 3 4 5
3/15 a b c d e f
and converts it to
3/15 12:00am a
3/15 1:00am b
3/15 2:00am c
and so on
SELECT dateadd(hour,cast(times AS int),date), cast(times AS int), value
FROM (SELECT date, [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
[11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23]
FROM b) AS p
UNPIVOT (value FOR times IN ([0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
[11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23]
)) AS s
date 0 1 2 3 4 5
3/15 a b c d e f
and converts it to
3/15 12:00am a
3/15 1:00am b
3/15 2:00am c
and so on
SELECT dateadd(hour,cast(times AS int),date), cast(times AS int), value
FROM (SELECT date, [0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
[11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23]
FROM b) AS p
UNPIVOT (value FOR times IN ([0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10],
[11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23]
)) AS s
Thursday, January 8, 2009
@_variable_in
When declaring input variables to a stored procedure in MS SQL Server, it is sometimes beneficial to use
@_variable_in instead of @variable_in
WITH (NOLOCK)
Using the NOLOCK hint can speed up queries by allowing the query to not wait while other queries are writing to the table. The downside is that your query can read data that may get rolled back.
FROM table1 a WITH (NOLOCK)
More info: http://msdn.microsoft.com/en-us/library/ms187373.aspx
FROM table1 a WITH (NOLOCK)
JOIN table 2 b WITH (NOLOCK) ON a.field = b.field
JOIN table3 c WITH (NOLOCK) ON b.field= c.field
JOIN table4e WITH (NOLOCK)
More info: http://msdn.microsoft.com/en-us/library/ms187373.aspx
Subscribe to:
Posts (Atom)