What is the maximum characters for the NVARCHAR(MAX)? [duplicate]

The max size for a column of type NVARCHAR(MAX) is 2 GByte of storage. Since NVARCHAR uses 2 bytes per character, that’s approx. 1 billion characters. Leo Tolstoj’s War and Peace is a 1’440 page book, containing about 600’000 words – so that might be 6 million characters – well rounded up. So you could … Read more

Script to kill all connections to a database (More than RESTRICTED_USER ROLLBACK)

Updated For MS SQL Server 2012 and above USE [master]; DECLARE @kill varchar(8000) = ”; SELECT @kill = @kill + ‘kill ‘ + CONVERT(varchar(5), session_id) + ‘;’ FROM sys.dm_exec_sessions WHERE database_id = db_id(‘MyDB’) EXEC(@kill); For MS SQL Server 2000, 2005, 2008 USE master; DECLARE @kill varchar(8000); SET @kill=””; SELECT @kill = @kill + ‘kill ‘ … Read more

How do I move a table into a schema in T-SQL

ALTER SCHEMA TargetSchema TRANSFER SourceSchema.TableName; If you want to move all tables into a new schema, you can use the undocumented (and to be deprecated at some point, but unlikely!) sp_MSforeachtable stored procedure: exec sp_MSforeachtable “ALTER SCHEMA TargetSchema TRANSFER ?” Ref.: ALTER SCHEMA SQL 2008: How do I change db schema to dbo

Can I use multiple “with”?

Try: With DependencedIncidents AS ( SELECT INC.[RecTime],INC.[SQL] AS [str] FROM ( SELECT A.[RecTime] As [RecTime],X.[SQL] As [SQL] FROM [EventView] AS A CROSS JOIN [Incident] AS X WHERE patindex(‘%’ + A.[Col] + ‘%’, X.[SQL]) > 0 ) AS INC ), lalala AS ( SELECT INC.[RecTime],INC.[SQL] AS [str] FROM ( SELECT A.[RecTime] As [RecTime],X.[SQL] As [SQL] FROM … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)