Convert datetime to string in format dd-MM-yyyy in T-SQL
convert(varchar(10),getdate(),105) Result 26-11-2010
convert(varchar(10),getdate(),105) Result 26-11-2010
If you have a table in a Microsoft SQL Server database with an integer column that contains rows and you want to update the existing rows to contain consecutive numbers, you can use the following
If you want to create a corresponding SQL Server database table, from a ODBC table, you can use the following C# function: Note This function is not bullet proof, but gives you a simple example:
If you are using SqlCacheDependency in you’re ASP .NET website, the database must have SQL Server Broker enabled. To enable SQL Server Broker on a SQL Server 2005 database use: USE master GO ALTER DATABASE
When you have many databases on a database development SQL server and these databases are re-creatable, you can save space by setting the recovery model for all databases to Simple, truncate and shrink the log
If you want to close all connections to a database, you can use the following TSQL code: USE MyDatabase GO ALTER DATABASE MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO — Set some options or
There are two options for adding a “not null” column to a table using t-sql alter table statement in Microsoft SQL Server. Add a default to the new column, which sets the value of existing
If you want to change the value of default on a column, you must use the ALTER TABLE syntax (DROP DEFAULT and CREATE DEFAULT should be avoided, will be removed in future releases): -- Create
To get the first day of the current week use: select dateadd(dd, (datepart(dw, getdate()) * -1) + 2, getdate()) To get the first day of previous week and last day of previous week use: select
This post will be edited each time I find a best practice for TSQL Never use <,>,<=,=> on datetime, always use datediff