SQL Server Foreign Key Constraints – sp_fkeys on ‘Roids!

This query gives you enough information to recreate a foreign key. Enjoy!

--===========================================
--Returns what you need to recreate foreign
-- keys. SP_FKEYS on steriods...
--===========================================

SELECT
SCHEMA_NAME(fk.schema_id) + '.' + OBJECT_NAME(fk.parent_object_id) as [Primary Table Name],
fk.name as [Foreign Key Name],
OBJECT_NAME(fk.referenced_object_id) as [Foriegn Key Table Name],
fkcol.name as [Foriegn Key Column Name],
pkcol.name as [Primary Table Column Name]
FROM
sys.foreign_keys fk
INNER JOIN sys.columns fkcol
ON fkcol.object_id = fk.referenced_object_id AND fkcol.column_id = fk.key_index_id
INNER JOIN sys.foreign_key_columns pk
ON pk.constraint_object_id = fk.object_id
INNER JOIN sys.columns pkcol
ON pkcol.object_id = pk.parent_object_id AND pkcol.column_id = parent_column_id
WHERE OBJECT_ID('insert table name here') = fk.parent_object_id

 

Fun With Images and Photographs – Photosynth

This is very interesting and compelling. Anyone have an other great ideas for processing of images? What are your plans for images? I would love to hear them as I am planning my own project similar to this one but to a different end and for a different purpose.

Powershell – Top Command

For those of you who love the top command in Linux…

 

function Get-Top{

#######################################

##Get-Top

##

##Written By: John Glasgow

#######################################

<#

.SYNTAX

Get-Top [-delay interval] [-pid pid_number]

 

.SYNOPSIS

Emulates the top command from Linux/Unix.

 

.EXAMPLE

To set delay of 5 seconds.

Get-Top -delay 5

 

.EXAMPLE

To watch a particular process.

Get-Top -pid 4408

#>

$delay = 2

$proc = -1

 

for($i = 0; $i -lt $args.Count; $i += 1){

if( $args[$i] -ilike “-d*” ){

$i++

$delay = $args[$i]

}

if( $args[$i] -ilike “-p*” ){

$i++

$proc = $args[$i]

}

if( $args[$i] -ilike “-q*” ){

$i++

$delay = 0

}

}

 

while ($true){

Clear-Host

if($proc -gt 0){Get-Process | Sort-Object -Descending cpu | Where-Object{ $_.Id -eq $proc } | Format-Table}

else{Get-Process | Sort-Object -Descending cpu | Select-Object -First 20 | Format-Table}

Start-Sleep -Seconds $delay

}

}

Set-Alias top Get-Top

PowerGUI – Using Powershell to get Disk Space

This is a script you can use in PowerGUI as a script node. This handy little script will give you the basic information of your drives so you can figure out if you disks are going to run out of space! I had to make a modification to this script, it works much better now! I apologize to everyone who was using the older script, which works well in Powershell but not PowerGUI.

Note: This will work with your existing credentials.

[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null
$name = [Microsoft.VisualBasic.Interaction]::Inputbox(“Enter the IP or Name of the server:”)

$drives = gwmi win32_logicaldisk -ComputerName $name | where{ $_.drivetype -eq 3 }
$driveArray = @()
$counter = 0
foreach ($drive in $drives){
$driveArray += New-Object -TypeName System.Object
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name name -Value $drive.Name
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name percentfree -Value ([int] [System.Math]::Round(($drive.FreeSpace) / $drive.Size * 100))
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name sizeGB -Value ([int]($drive.Size / 1Gb))
$driveArray[$counter] | Add-Member -MemberType NoteProperty -Name freespaceGB -Value ([int]($drive.FreeSpace / 1Gb))
$counter +=1
}
$driveArray | Format-Table

A slimmed down version for the Powershell console can be found here: Console Script

I also made a system monitoring script, free for you to use.

If you found this useful, subscribe to my blog.

PowerGUI – Powershell SQL Server Database Information Script Node

This short script will prompt you for the name or IP of the server you wish to connect to. As long as you have the correct rights to that server you can use this script. Hope this helps Fernando!

[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.SqlServer.SMO’) | Out-Null
[System.Reflection.Assembly]::LoadWithPartialName(‘Microsoft.VisualBasic’) | Out-Null
$name = [Microsoft.VisualBasic.Interaction]::Inputbox(“Enter the IP or Name of the server:”)
$server = New-Object(‘Microsoft.SqlServer.Management.Smo.Server’) $name
$server.Databases | format-table Name,Size,RecoveryModel,PrimaryFilePath -AutoSize

If you found this useful, subscribe.

Microsoft Access Reports Printer Settings

Problem

Here is something interesting I have run across. I sometimes write reports in an Access database. As soon as I transfer the report over to the client’s computer, the computer appears to lose its default printer settings.

Background

As it turns out, Access remembers your printer settings from the last time you ran the job. I have also found that if you have a different printer installed than where the report is going to be used, it will lose the settings. So if you need a certain behavior to occur like duplex printing do the following:

Solution

  1. Go to the client’s computer which is going to run the report.
  2. Open the report in design view and make any changes you need.
  3. Ctrl-P to bring up the print dialog, make any changes you need for the printers configuration (you are re-establishing the desired printing setting here.
  4. Print one or two pages.
  5. Save the report.

This will hopefully save you some time in you MS Access reporting.

Unrecognized configuration section userSettings.

Ok so you might find this interesting. I was changing one of my dot net programs lately to no longer rely on user settings. Once I deleted all user settings, I received the following error: “Unrecognized configuration section userSettings”.
The solution to this is to load the user.config file into notepad and delete the entire userSettings section from the file.  Then rebuild your program and it will work again.