Tuesday, September 11, 2007
A compendium of short cuts, tips and tricks, features, whatcha-may-callits for the Visual Studio .NET IDE.
Friday, September 7, 2007
CSS2 Reference
Left Join vs Left outer Join - Join vs Inner Join
Tuesday, August 21, 2007
Can't truncate table with Foreign Key
When trying to truncate a table that is referenced by a Foreign Key I always get this message, even if the table referencing the primary table is empty.
Server: Msg 4712, Level 16, State 1, Line 1
Cannot truncate table 'actTouches' because it is being referenced by a FOREIGN KEY constraint.
To get around this problem I simply delete all rows from the table then re seed the identity column with 1.
Delete From [table]
Go
DBCC CheckIdent ([table], RESEED, 1)
Go
Server: Msg 4712, Level 16, State 1, Line 1
Cannot truncate table 'actTouches' because it is being referenced by a FOREIGN KEY constraint.
To get around this problem I simply delete all rows from the table then re seed the identity column with 1.
Delete From [table]
Go
DBCC CheckIdent ([table], RESEED, 1)
Go
How to Insert Values into an Identity Column in SQL Server
Identity columns are commonly used as primary keys in database tables. These columns automatically assign a value for each new row inserted. But what if you want to insert your own value into the column? It's actually very easy to do.
The trick is to enable IDENTITY_INSERT for the table. That looks like this:
SET IDENTITY_INSERT IdentityTable ON
INSERT IdentityTable(TheIdentity, TheValue)
VALUES (3, 'First Row')
SET IDENTITY_INSERT IdentityTable OFF
Here are some key points about IDENTITY_INSERT
* It can only be enabled on one table at a time. If you try to enable it on a second table while it is still enabled on a first table SQL Server will generate an error.
* When it is enabled on a table you must specify a value for the identity column.
* The user issuing the statement must own the object, be a system administrator (sysadmin role), be the database owner (dbo) or be a member of the db_ddladmin role in order to run the command.
Read the full article for more information. For instance the fact that this can modify the identity properties of your column depending on the values you update the table with.
Monday, August 20, 2007
SQL Server linked servers by IP
I struggled for quite a little while trying to execute this:
Select top 1 * From [xxx.xxx.xxx.xxx].[db].[owner].[table]
In SQL2005 Management Studio against a SQL2000 box.
And receiving this:
An error occurred while executing batch. Error message is: Processing of results from SQL Server failed because of an invalid multipart name "xxx.xxx.xxx.xxx.db.owner.table", the current limit of "4" is insufficient.
I was unable to link the servers by name since there was no DNS to resolve it.
I finally discovered that I didn't receive the error if I simply used SQL 2000's Query analyzer. I was a little surprised to find that this issue in backwards compatibility existed in the Management Studio. I have not had a chance to test a SQL 2005 linked server to see if an IP address causes the same issue on it, though I would hope that it wouldn't.
Note: I just discovered that I was able to use OPENQUERY in Management Studio to run my query from one SQL2000 server to a linked SQL2000 server.
SELECT * FROM OPENQUERY([xxx.xxx.xxx.xxx], 'SELECT * FROM [db].owner.[table]') AS tablename
Select top 1 * From [xxx.xxx.xxx.xxx].[db].[owner].[table]
In SQL2005 Management Studio against a SQL2000 box.
And receiving this:
An error occurred while executing batch. Error message is: Processing of results from SQL Server failed because of an invalid multipart name "xxx.xxx.xxx.xxx.db.owner.table", the current limit of "4" is insufficient.
I was unable to link the servers by name since there was no DNS to resolve it.
I finally discovered that I didn't receive the error if I simply used SQL 2000's Query analyzer. I was a little surprised to find that this issue in backwards compatibility existed in the Management Studio. I have not had a chance to test a SQL 2005 linked server to see if an IP address causes the same issue on it, though I would hope that it wouldn't.
Note: I just discovered that I was able to use OPENQUERY in Management Studio to run my query from one SQL2000 server to a linked SQL2000 server.
SELECT * FROM OPENQUERY([xxx.xxx.xxx.xxx], 'SELECT * FROM [db].owner.[table]') AS tablename
Tuesday, August 14, 2007
DataGrid Default Paging
Subscribe to:
Posts (Atom)