integer Max value constants in SQL Server T-SQL?
There are two options: user-defined scalar function properties table In Oracle, you can do it within Packages – the closest SQL Server has is Assemblies…
There are two options: user-defined scalar function properties table In Oracle, you can do it within Packages – the closest SQL Server has is Assemblies…
INSERT INTO <table> SELECT <natural keys>, <other stuff…> FROM <table> WHERE NOT EXISTS — race condition risk here? ( SELECT 1 FROM <table> WHERE <natural keys> ) UPDATE … WHERE <natural keys> there is a race condition in the first INSERT. The key may not exists during the inner query SELECT, but does exist at … Read more
A non-committed transaction can be reverted by issuing the command ROLLBACK But if you are running in auto-commit mode there is nothing you can do….
Index seek, every time. Lookups are expensive, so this is covering indexes and especially the INCLUDE clause was added to make them better. Saying that if you expect exactly one row, for example, a seek followed a lookup can be better than trying to cover a query. We rely on this to avoid yet another … Read more
Assuming this is actually a composite key, since you can’t have 2 primary keys… The error message tells you exactly what to do, namely add an order. You can do this by adding [Column(Order = 0)] and [Column(Order = 1)] to your key columns. For your example: public class LineItem { [Key][Column(Order = 0)] public … Read more
You can use this script: IF EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_NAME]’) AND parent_object_id = OBJECT_ID(N'[dbo].[MyTable]’)) BEGIN — do stuff END This can be done if you expand out the table and right click on an existing FK and choose script key as “DROP TO” and then you will get a generated … Read more
SELECT DATEADD(minute, -15, ‘2000-01-01 08:30:00′); The second value (-15 in this case) must be numeric (i.e. not a string like ’00:15′). If you need to subtract hours and minutes I would recommend splitting the string on the : to get the hours and minutes and subtracting using something like SELECT DATEADD(minute, -60 * @h – … Read more
ALTER TABLE tablename ALTER COLUMN columnname datatype NOT NULL You will obviously have to make sure that the column does not contain any NULL values before doing this. E.g. ALTER TABLE orders ALTER COLUMN customer_id INT NOT NULL
select * into #TempTable from SomeTale select * from #TempTable
order by LEN(value), value Not perfect, but works well in a lot of cases.