Skip to content

Instantly share code, notes, and snippets.

View robsonalves's full-sized avatar
🏠
Working from home

Robson Alves robsonalves

🏠
Working from home
View GitHub Profile
@robsonalves
robsonalves / migratingRepo.sh
Created April 5, 2019 10:07
Script to migrate Repostories Git on DevOpsAzure - Including All Branches
#!/bin/bash
clear
REPOS=(teste teste1 teste2)
git=https://user:password@{organizationName}.visualstudio.com/{TeamProject}/_git/
newRepo=https://user:password@{organizationName}.visualstudio.com/{TeamProject}/_git/
for i in ${REPOS[@]}
do
echo $git$i
@robsonalves
robsonalves / sh
Created October 30, 2018 23:04
Create a partiton file
tail -n +2 YOURFILE.csv/txt | split -l 1000 -d --additional-suffix=.csv - split_
for file in split_*
do
head -n 1 YOURFILE.csv/txt > tmp_file
cat $file >> tmp_file
mv -f tmp_file $file
done
@robsonalves
robsonalves / FTPConfig.ps1
Created May 12, 2017 13:16
Config FTP windows server via PS
Import-module servermanager
Add-WindowsFeature web-server –includeallsubfeature
Import-Module WebAdministration
New-WebFtpSite -Name "LinxFTP" -Port "21" -Force
cmd /c \Windows\System32\inetsrv\appcmd set SITE "LinxFTP" "-virtualDirectoryDefaults.physicalPath:C:\inetpub\ftproot"
Set-ItemProperty "IIS:\Sites\LinxFTP" -Name ftpServer.security.ssl.controlChannelPolicy -Value 0
@robsonalves
robsonalves / gist:2d04495807c667c287cb
Last active February 23, 2016 18:11
Detach and attach via CMD
USE MASTER;
GO
-- Take database in single user mode -- if you are facing errors
-- This may terminate your active transactions for database
ALTER DATABASE Piloto
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO
-- Detach DB
EXEC MASTER.dbo.sp_detach_db @dbname = N'Piloto'
@robsonalves
robsonalves / gist:eb82c0c4ee56d661e441
Created February 23, 2016 11:13
SQL Server - Querys Pesadas
use [database]
go
select total_worker_time/execution_count as MediaCPU
, total_worker_time AS TotalCPU
, total_elapsed_time/execution_count as MediaDuration
, total_elapsed_time AS TotalDuration
, total_logical_reads/execution_count as MediaLogicalReads
, total_logical_reads AS TotalLogicalReads
, total_physical_reads/execution_count as MediaPhysicalReads
, total_physical_reads AS TotalPhysicalReads
@robsonalves
robsonalves / rebuildALLIndex.sql
Last active October 23, 2015 17:05
Rebuild all indexes to change fill factor
DECLARE @TableName VARCHAR(255)
DECLARE @sql NVARCHAR(500)
DECLARE @fillfactor INT
SET @fillfactor = 80
DECLARE TableCursor CURSOR FOR
SELECT OBJECT_SCHEMA_NAME([object_id])+'.'+name AS TableName
FROM sys.tables
OPEN TableCursor
FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
@robsonalves
robsonalves / indexmissingListIndex.sql
Created October 21, 2015 18:40
Returning Index Missing and List of Idexes
set transaction isolation level read uncommitted
select DB_NAME(database_id) as DataBaseName
, count(*) as [Missing Index Count]
from sys.dm_db_missing_index_details
group by db_name(database_id)
order by [Missing Index Count] desc
@robsonalves
robsonalves / Remover All Columns.sql
Last active October 21, 2015 15:57
Remover All Columns
declare @query varchar(max) = ''
DECLARE @Remove nvarchar(1000)
select 'ALTER TABLE '+ a.name + ' drop column ' + b.name + '' as Remove
into #temp
from sys.tables a
inner join sys.columns b on b.object_id = a.object_id
where b.name like '%ROW%'
@robsonalves
robsonalves / indiceseconversao.sql
Last active October 21, 2015 13:34
Encontrar Falta de Indices e Conversão Implicita
SET TRANSACTION isolation level READ uncommitted
SELECT TOP 20 ST.text AS [PARENT QUERY],
Db_name(ST.dbid) AS [ DATABASENAME ],
CP.usecounts AS [USAGE COUNT],
QP.query_plan
FROM sys.dm_exec_cached_plans CP
CROSS apply sys.Dm_exec_sql_text(CP.plan_handle) ST
CROSS apply sys.Dm_exec_query_plan(CP.plan_handle) QP
WHERE Cast(QP.query_plan AS NVARCHAR(max)) LIKE '%<MissingIndexes>%' or
@robsonalves
robsonalves / IndexesNaoUtilizados.sql
Last active October 21, 2015 13:22
Indexes não utilizados
select
db_name() as DataBaseName
,SCHEMA_NAME(O.schema_id) as SchemaNAme
,OBJECT_NAME(I.object_id) as TableName
,I.Name as IndexName
from sys.indexes I
inner join sys.objects O on I.object_id = O.object_id
left outer join sys.dm_db_index_usage_stats S on S.object_id = I.object_id
and I.index_id = S.index_id and database_id = DB_ID()
where OBJECTPROPERTY(o.object_id,'IsMsShipped') = 0