How to ALTER multiple columns at once in SQL Server

I need to ALTER the data types of several columns in a table. For a single column, the following works fine: ALTER TABLE tblcommodityOHLC ALTER COLUMN CC_CommodityContractID NUMERIC(18,0) But how do I alter multiple columns in one statement? The following does not work: ALTER TABLE tblcommodityOHLC ALTER COLUMN CC_CommodityContractID NUMERIC(18,0), CM_CommodityID NUMERIC(18,0) 13 Answers 13

How to check existence of user-define table type in SQL Server 2008?

I have a user-defined table type. I want to check it’s existence before editing in a patch using OBJECT_ID(name, type) function. What type from the enumeration should be passed for user-defined table types? N’U’ like for user defined table doesn’t work, i.e. IF OBJECT_ID(N’MyType’, N’U’) IS NOT NULL 5 Answers 5

Alter column, add default constraint

I have a table and one of the columns is “Date” of type datetime. We decided to add a default constraint to that column Alter table TableName alter column dbo.TableName.Date default getutcdate() but this gives me error: Incorrect syntax near ‘.’ Does anyone see anything obviously wrong here, which I am missing (other than having … Read more

Multi-statement Table Valued Function vs Inline Table Valued Function

A few examples to show, just incase: Inline Table Valued CREATE FUNCTION MyNS.GetUnshippedOrders() RETURNS TABLE AS RETURN SELECT a.SaleId, a.CustomerID, b.Qty FROM Sales.Sales a INNER JOIN Sales.SaleDetail b ON a.SaleId = b.SaleId INNER JOIN Production.Product c ON b.ProductID = c.ProductID WHERE a.ShipDate IS NULL GO Multi Statement Table Valued CREATE FUNCTION MyNS.GetLastShipped(@CustomerID INT) RETURNS @CustomerOrder … Read more