T-SQL

SQL_icon_base.jpgWhen you try alter column in MSSQL 2005 from one datatype to other with some default value by ALTER TABLE xxx ALTER COLUMN column_name you get error about existing constraint. Unfortunately there is nothing like CASCADE CONSTRAINT. You must DROP constraint first and then you can ALTER column and finally you have to create CONSTRAINT again. I will show you easy way, how to do it.

SQL_icon_base.jpgCommon situation, you need to make same changes in database, and you have column name.  But you aren't sure in which tables this column is, where to look etc. Here is the simple solution.

SQL_icon_base.jpgWhen you try drop column in MSSQL 2005 with some default value by ALTER TABLE xxx DROP column_name you get error about existing constraint. Unfortunately there is nothing like CASCADE CONSTRAINT. You must DROP constraint first and then you can DROP column. I will show you the easiest way, how to do it.
 

cofee_book.png In previous content I showed how to use the OUTPUT command for printing inserted or updated records in a T-SQL query. It's simple, it's powerfull and saves us lines of code. Usually we need use these values in some larger script and assigned them to variables or insert them into other tables. Let's see how to do it.

OUTPUT Command in MSSQL 2005In MSSQL 2005 is new T-SQL command OUTPUT, that was used only as output parameters in previous MSSQL version. Now you can use it in T-SQL commands to make data changes and see results by one command without using Triggers.