随笔分类 - SQLServer
摘要:SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '')The below script removes the TAB(Horozontal Tab), Line feed(New line), Carriage Return Charac...
阅读全文
摘要:1.--查询数据库状态 select name,user_access,user_access_desc,snapshot_isolation_state,snapshot_isolation_state_desc,is_read_committed_snapshot_on from sys.dat...
阅读全文
摘要:When you using sqlcmd to export some data by a query, you will found some column data is truncated if it is a ntext/text/varch(max)/nvarchar(max).the ...
阅读全文
摘要:Student表有三列,分别是姓名、课程、成绩 Name Curricula Mark 张三 语文 70 李四 数学 80 王朝 英语 59 城南 马哲 70 王朝 语文 90 我想得到的效果...
阅读全文
摘要:1. enable traceDBCC TRACEON (trace# [ ,...n ][ , -1 ] ) [ WITH NO_INFOMSGS ]trace# Is the number of the trace flag to turn on.n Is a placeholder that...
阅读全文
摘要:Running total for Oracle:SELECT somedate, somevalue,SUM(somevalue) OVER(ORDER BY somedateROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)AS RunningTo...
阅读全文
摘要:CREATE PROCEDURE SP_EXEC_WITH_LOG(@I_TICKETNO VARCHAR(10),@I_SQLSTR nvarchar(max))ASBEGIN DECLARE @QUOTATION_TRANSFER_STR nvarchar(max); SET @QUOTATIO...
阅读全文
摘要:原始代码如下:begin DECLARE @SQL_STMT NVARCHAR(300),@V_CLIENT_ID INT,@V_PGNAME VARCHAR(1000),@V_LOGID INT;DECLARE C2 CURSOR FOR SELECT PGNAME,CLIENT_ID FROM ...
阅读全文
摘要:原SQL如下:SQL的主要问题是红色部分居然通过标量查询,反复的查找与SQL相同的基表,很显然这个可以用case when来简化。select a.TRAN_ID,a.AMOUNT,a.BALANCE,a.INVAMT,a.PROMISED,a.INVNO,a.RCLNUM,b.PROBLEM_ID...
阅读全文
摘要:DECLARE @page INT, @size INT;select @page = 300, @size = 10SELECT *FROM gpcomp1.GPCUSTWHERE company like 'a%'ORDER BY CUSTNOOFFSET (@page -1) * @size ...
阅读全文
摘要:use masterIF EXISTS (SELECT * FROM sys.databasesWHERE name = 'gpdb83sp')BEGINDROP DATABASE gpdb83spEND;CREATE DATABASE gpdb83spON( NAME = gpdb83sp_dat...
阅读全文
摘要:There are three DMVs you can use to track tempdb usage:sys.dm_db_task_space_usagesys.dm_db_session_space_usagesys.dm_db_file_space_usageThe first two ...
阅读全文
摘要:select r.ring_buffer_address,r.ring_buffer_type,dateadd (ms, r.[timestamp] - sysinfo.sqlserver_start_time_ms_ticks, sysinfo.sqlserver_start_time) as r...
阅读全文
摘要:Balancing CPU and I/O throughput is essential to achieve good overall performance and to maximize hardware utilization. SQL Server includes two asynch...
阅读全文
摘要:1. Grant necessory permission to user account, so it can use SQL profiler.USE masterGRANT ALTER TRACE TO TEST;GRANT VIEW SERVER STATE TO TEST;USE test...
阅读全文
摘要:SET SHOWPLAN_ALL { ON | OFF }It will not execute the TSQL statements.It cannot be specified inside a stored procedure,must be the only statements in a...
阅读全文
摘要:1.Enable the change tracking at the database level.ALTER DATABASE AdventureWorks2008 SET CHANGE_TRACKING = ON;By Default retention is 2 dyas with auto...
阅读全文
摘要:1.DMV Query to identify all active SQL Server SessionsThe query below identifies all currently active SQL Server user connections by their SQL Server ...
阅读全文
摘要:Summary Info:Logical Reads : Reading Data pages from CachePhysical Reads : Reading Data pages from Hard DiskBuffer Cach Hit Ratio: (logical reads – ...
阅读全文
摘要:The Transact-SQL programming language provides several SET statements that change the current session handling of specific information. The SET statem...
阅读全文
浙公网安备 33010602011771号