Reseed to next Id available in SQL Server
DECLARE @MaxId INT SELECT @MaxId = max([Id]) FROM [MyTable] if @MaxId IS NULL SET @MaxId = 0 DBCC CHECKIDENT (‘[MyTable]’, RESEED, @MaxId)
DECLARE @MaxId INT SELECT @MaxId = max([Id]) FROM [MyTable] if @MaxId IS NULL SET @MaxId = 0 DBCC CHECKIDENT (‘[MyTable]’, RESEED, @MaxId)
SELECT TOP 100 QueryState.execution_count, OBJECT_NAME(objectid), query_text = SUBSTRING( qt.text, QueryState.statement_start_offset / 2, ( CASE WHEN QueryState.statement_end_offset = -1 THEN len(convert(nvarchar(max), qt.text)) * 2 ELSE QueryState.statement_end_offset END – QueryState.statement_start_offset ) / 2 ), qt.dbid, dbname =…
Simple copy-and-paste example: DECLARE @timestamp BIGINT = 1661881445; SELECT DATEADD(S, @timestamp, ‘1970-01-01’) Or for values greater than 2147483647 DECLARE @t AS BIGINT = 4956739375 DECLARE @oneyear AS INT = 31622400 SELECT DATEADD(SECOND, @t % @oneyear,…
SELECT client_net_address, COUNT(*) FROM sys.dm_exec_connections GROUP BY client_net_address
We have released a free, fast, advertising-free and 100% client side SQL code formatter. Try it now! SQL Formatter.
SELECT [so].[name] AS [Name], User_name([so].[uid]) AS [Owner], User_name([so2].[uid]) AS [Schema], Object_name([so].[parent_obj]) AS [TableName], Objectproperty([so].[id], ‘execisupdatetrigger’) AS [IsUpdate], Objectproperty([so].[id], ‘execisdeletetrigger’) AS [IsDelete], Objectproperty([so].[id], ‘execisinserttrigger’) AS [IsInsert], Objectproperty([so].[id], ‘execisaftertrigger’) AS [IsAfter], Objectproperty([so].[id], ‘execisinsteadoftrigger’) AS [IsInsteadOf], Objectproperty([so].[id], ‘execistriggerdisabled’)…
Here’s a little script in T-SQL to find queries running in our SQL SERVER database: SELECT sqltext.TEXT, res.session_id, res.status, res.command, res.cpu_time, res.total_elapsed_time FROM sys.dm_exec_requests res CROSS APPLY sys.dm_exec_sql_text(sql_handle) AS sqltext This script is also useful…
CREATE FUNCTION dbo.MyFunction (@input VARCHAR(200)) RETURNS VARCHAR(200) AS BEGIN DECLARE @WebSite VARCHAR(250) SET @WebSite = @Input SET @WebSite = REPLACE(@WebSite , ‘https://’, ”) SET @WebSite = REPLACE(@WebSite , ‘http://’, ”) SET @WebSite = REPLACE(@WebSite ,…
Often a good example is worth more than 1000 words. Here’s how to run, on Sql Server, one for each / while in Transact Sql. DECLARE @Id INT DECLARE @Name NVARCHAR(50) DECLARE @LastName NVARCHAR(50) DECLARE…