-
Recent Posts
Recent Comments
Archives
- July 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
- October 2010
- June 2010
- May 2010
- December 2009
- November 2009
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
Categories
- .Net
- ActiveSync
- Art
- ASP.Net
- Attitude
- BBC Micro
- Best Practice
- Blogging
- Body
- Book Reviews
- Books
- C#
- Clutter
- Complaints
- Computing
- Covey
- Customer Service
- Definitions
- Design
- Design Patterns
- Discrimination
- Excellence
- Faith
- Family Life
- Fear
- Fitness
- Goals
- Graphics
- Group activities
- Health
- Humour
- Identity
- Internet Explorer
- Investment
- IT
- J2ME
- JB
- Leadership
- Legacy
- Leisure
- Life
- Link
- Memory
- Microsoft Word
- Mind
- Money
- Motivation
- Moving House
- MS Word
- Name
- Operating Systems
- Orange
- Orange M3100
- Otto Project
- Painting
- Personal Development
- Personal Finance
- Phone
- Poetry
- Poor Customer Service
- Poverty
- prayer
- Product Ideas
- Productivity
- Progamming
- Programming
- Purpose
- Quote
- Quotes
- Recruitment
- Relationships
- Religion
- Reputation
- Retro Computing
- Review
- Running
- Sexism
- Spell Checker
- Spirit
- SQL Server
- Stewardship
- Stuff
- Teaching
- Technology
- Temptation
- Thinking
- Time
- Time Management
- Uncategorized
- Utils
- Values
- VB.Net
- VBScript
- Violence
- Visual Source Safe
- Visual Studio
- Web Design
- Wisdom
- WM5
- WM6
- Words
- Work
- Working Out
- Writing
Meta
Category Archives: SQL Server
SQL Server: Example Naming Convention
An example of a SQL Server naming convention I have encountered: Tables tcTableName (e.g. tcAsset) for core tables, i.e. tables that contain regularly changing data and have insert/update/delete queries run against them. trTableName (e.g. trAssetType) for reference tables, i.e. tables … Continue reading
Posted in SQL Server
Leave a comment
SQL Server: Disable All Constraints
To disable all constraints on all tables in a database: EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all" To enable all constraints on all tables in a database: exec sp_msforeachtable @command1="print '?'", @command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
Posted in SQL Server
Leave a comment
SQL Server: Drop all Foreign Keys that Reference a Table
Introduction Before you drop a table in SQL Server, you must first drop all the foreign keys that reference that table. The following SQL scripts may help with this task. Step 1: Run the following to create a Stored Procedure … Continue reading
Posted in SQL Server
Leave a comment
SQL Server: Show all the FOREIGN KEYS that reference a TABLE
For SQL 2005+ DECLARE @tableName nvarchar(MAX) SET @tableName = 'tableName' — (1) SELECT DISTINCT ccu.table_name, ccu.constraint_name FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc ON rc.unique_constraint_name = tc.constraint_name INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu ON … Continue reading
Posted in SQL Server
Leave a comment
SQL Server: Show all the PRIMARY KEYS for a TABLE
For SQL Server 2005 + DECLARE @tableName nvarchar(MAX) SET @tableName = 'tableName' — (1) SELECT tc.TABLE_NAME, tc.CONSTRAINT_NAME, kcu.COLUMN_NAME, kcu.ORDINAL_POSITION FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME WHERE tc.CONSTRAINT_TYPE = 'PRIMARY KEY' AND tc.TABLE_NAME = @tableName OR … Continue reading
Posted in SQL Server
Leave a comment
SQL: WHEN CASE NULL Fails
Imagine you want to find all the null values in a column in a database table (SQL Server). x 1 2 NULL 4 5 Here is the SQL that performs the task as required: SELECT x, CASE x WHEN NULL … Continue reading
Posted in SQL Server
32 Comments
SQL Server: Change Owner of an Object
Like this: sp_changeobjectowner '<objectname>', '<newownername>'
Posted in SQL Server
Leave a comment
SQL Server: Case Sensitive Query
Someone at work sent this out to the team. From LW: Dear All, you might find this bit of code quite useful. I was trying to find data within a table where the data was like lower case letters e.g … Continue reading
Posted in SQL Server
Leave a comment