SQL 2008 Enable Changes To Tables

12 Comments » by Jon Hibbins on 8 October 2008
Filed under: Database, MSSQL2008, SQL Server, TSQL

If you get the error in the SQL 2008 Management Studio :

“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.”

You can enable changes inside the Microsoft SQL Server Management Studio by going to ‘Tools|Options|Designers’ then unchecking the ‘Prevent saving changes that require table re-creation’ option

Autostart Zend Core on Ubuntu

No Comments » by Jon Hibbins on 18 September 2008
Filed under: MySQL, PHP, Platform, Unix/Linux

This is the 2nd time I have had to search for starting up Zend Core automatically on Ubuntu Workstation, so here is the answer:

First change the permissions of /etc/rc.local by opening a terminal window (Applications|Accessories|Terminal) and enter the following command:

sudo chmod 777 /etc/rc.local

Then open this file with the text editor (Applications|Accessories|Text Editor) and put the following text before the exit 0 command

cd /usr/local/Zend/Core/mysql && ./bin/safe_mysqld &
/usr/local/Zend/apache2/bin/apachectl start &

Zend Core, PHP and MySQL should now all start automaticaly at boot time.

TSQL Count Number Of Stored Procedures, Views, Tables or Functions

13 Comments » by Jon Hibbins on 4 September 2008
Filed under: Code, Database, MSSQL2005, MSSQL2008, SQL Server, Software Development, TSQL

You can use TSQL to Count Number Of Stored Procedures, Views, Tables or Functions in a Database by using the Database INFORMATION_SCHEMA view

/* Count Number Of Tables In A Database */
    SELECT COUNT(*) AS TABLE_COUNT FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_TYPE='BASE TABLE'
    /* Count Number Of Views In A Database */
    SELECT COUNT(*) AS VIEW_COUNT FROM INFORMATION_SCHEMA.VIEWS
    /* Count Number Of Stored Procedures In A Database */
    SELECT COUNT(*) AS PROCEDURE_COUNT FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE'
    /* Count Number Of Functions In A Database */
    SELECT COUNT(*) AS FUNCTION_COUNT FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'

The same methodology can be used to query for information :

/* Select Table Information For A Database */
    SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
    /* Select View Information For A Database */
    SELECT * FROM INFORMATION_SCHEMA.VIEWS
    /* Select Stored Procedure Information For A Database */
    SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'PROCEDURE'
    /* Select Function Information For A Database */
    SELECT * FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_TYPE = 'FUNCTION'

SQL Server – TSQL DISTINCT or GROUP BY?

1 Comment » by Jon Hibbins on 3 September 2008
Filed under: Code, Database, MSSQL2005, MSSQL2008, SQL Server, Software Development, TSQL

DISTINCT v GROUP BY

A DISTINCT and GROUP BY usually generate the same query plan, so performance should be very simular or the same, if you only need to remove the dulicates then DISTINCT is easier to understand in the query, if you have a more complex query it may be worth running both and studdying the execution plan to see if your specific example wins

iPhone Developer Provision Issue on Device

7 Comments » by Jon Hibbins on 27 August 2008
Filed under: Objective-C, Quick Tips, iPhone

After a number of compile to iPhone device issues, specifically: “entitlement ‘application-identifier’ has value not permitted by provisioning profile” and “Command /usr/bin/codesign failed with exit code 1″, I have worked out you can have one and only one developer provision and developer application on the iPhone at a time otherwise you get installation errors etc…

I also had to have the correct Bundle Identifier in the Info.plist file and make sure the ‘Code Signing Identity’ and ‘Code Signing Provisioning Profile’ was also correct.

Hopefully this is useful to someone, Good Luck!!!

Objective-C Mod Command

No Comments » by Jon Hibbins on 22 August 2008
Filed under: Code, Objective-C, Quick Tips, Software Development, iPhone

If you are looking for the Objective-C Mod Command then look no further

To get the equivalent of a = b div c then :

a = b % c

Quick Tip: C# Current Application Version

2 Comments » by Jon Hibbins on 11 August 2008
Filed under: Quick Tips

Quick Tip: C# Current Application Version:

System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion;

Take a MSSQL database offline and back online with TSQL

1 Comment » by Jon Hibbins on 5 August 2008
Filed under: Code, Database, MSSQL2005, SQL Server, Software Development, TSQL

Take a database offline with TSQL:

– Kill All Other Users Processes And Set The Database To Single User Mode
ALTER DATABASE AdventureWorks
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE
– Take Offline
EXEC sp_dboption ‘AdventureWorks’, ‘offline’, ‘TRUE’

And restoring the database back to online with TSQL:

– Allow Users Back In By Setting Multi User Mode On
ALTER DATABASE AdventureWorks SET MULTI_USER
– Bring Back Online
EXEC sp_dboption ‘AdventureWorks’, ‘offline’, ‘FALSE’

C# Tip:Start an application from a C# program

No Comments » by Jon Hibbins on 3 August 2008
Filed under: .NET, C#, Code, MSSQL2005, Software Development

Useful code if you wish to launch an external application:

System.Diagnostics.Process.Start(@"C:\program files\microsoft office\word.exe", @"C:\MyWordDocument.docx");

Check if a SQL Server database exists or not (TSQL)

No Comments » by Jon Hibbins on 1 August 2008
Filed under: Code, Database, MSSQL2005, SQL Server, Software Development, TSQL

Here is a usefull TSQL Script for checking if a database exists :

– Check if the Database Exists
DECLARE @DatabaseCount AS int
SELECT @DatabaseCount=COUNT(*) FROM master.dbo.sysdatabases WHERE name=‘master’
SELECT @DatabaseCount AS [DatabaseCount]