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

How to Select Every Row Where Column Value is NOT Distinct

I need to run a select statement that returns all rows where the value of a column is not distinct (e.g. EmailAddress). For example, if the table looks like below: CustomerName EmailAddress Aaron [email protected] Christy [email protected] Jason [email protected] Eric [email protected] John [email protected] I need the query to return: Aaron [email protected] Christy [email protected] John [email protected] I … Read more

nvarchar(max) vs NText

What are the advantages and disadvantages of using the nvarchar(max) vs. NText data types in SQL Server? I don’t need backward compatibility, so it is fine that nvarchar(max) isn’t supported in older SQL Server releases. Edit: Apparently the question also applies to TEXT and IMAGE vs. varchar(max) and varbinary(max), for those searching for those data-types … Read more

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