This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;WITH tables_with_pk AS ( | |
SELECT t.table_schema, t.table_name | |
FROM INFORMATION_SCHEMA.TABLES t | |
INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc | |
ON t.TABLE_NAME = tc.TABLE_NAME AND t.table_schema = tc.table_schema | |
WHERE tc.constraint_type = 'PRIMARY KEY' | |
) | |
SELECT t.table_schema, t.table_name | |
FROM INFORMATION_SCHEMA.TABLES t | |
EXCEPT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
@IndexName varchar(300), | |
@SchemaName varchar(300), | |
@TableName varchar(300); | |
DECLARE inds CURSOR FAST_FORWARD FOR | |
SELECT DISTINCT | |
U.CONSTRAINT_NAME, | |
U.TABLE_SCHEMA, | |
U.TABLE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Criar todas os Default's | |
DECLARE @Command VARCHAR(MAX) | |
DECLARE curCommand CURSOR FOR | |
select | |
'ALTER TABLE ' + t.name + ' ADD CONSTRAINT DF_' + t.name + '_' + c.name + ' DEFAULT (' + d.definition + ') FOR ' + c.name | |
from sys.tables t | |
join sys.default_constraints d on d.parent_object_id = t.object_id | |
join sys.columns c on c.object_id = t.object_id and c.column_id = d.parent_column_id | |
OPEN curCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Gera script de padronização dos tamanho de todas as colunas numericas, com casas decimais. | |
*/ | |
SELECT 'ALTER TABLE ' + T.NAME + ' ALTER COLUMN ' + C.NAME + ' NUMERIC(20, 6) ' + CASE C.is_nullable WHEN 0 THEN 'NOT NULL' ELSE 'NULL' END--, * | |
FROM SYS.COLUMNS C | |
INNER JOIN SYS.TABLES T ON C.object_id = T.OBJECT_ID | |
--where C.NAME LIKE 'D%' and C.user_type_id <> 108 | |
WHERE (C.user_type_id = 108 /*NUMERIC*/ OR C.user_type_id = 106 /*DECIMAL*/) | |
--and C.precision > 1 | |
and C.scale > 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IF EXISTS ( | |
SELECT * | |
FROM sys.objects | |
WHERE object_id = OBJECT_ID(N'[dbo].[usf_rm_accent_pt_latin1]') | |
AND type IN (N'FN') | |
) | |
DROP FUNCTION usf_rm_accent_pt_latin1; | |
GO | |
CREATE FUNCTION usf_rm_accent_pt_latin1 (@txt varchar(max)) RETURNS varchar(max) | |
-- Nome Artefato/Programa..: usf_rm_accent_pt_latin1.sql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @Command VARCHAR(MAX) | |
DECLARE curCommand CURSOR FOR | |
SELECT | |
'ALTER TABLE ' + OBJECT_NAME(fk.parent_object_id) + ' DROP CONSTRAINT [' + RTRIM(fk.Name) + '];' | |
FROM sys.foreign_keys fk | |
OPEN curCommand | |
FETCH NEXT FROM curCommand INTO @Command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--Esta query ira realizar a reindexacao de todas as tabelas do Banco Selecionado. | |
EXEC sp_MSforeachtable @command1="DBCC DBREINDEX ('?', '', 70)" | |
--Fonte: https://robertobrandini.wordpress.com/2011/03/26/reindexar-tabelas-sql-server/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Introdução ao Terminal do Linux para Programadores | |
http://promo.visie.com.br/curso-terminal?p=suissa | |
Microsoft Virtual Academy - Microsoft | |
http://www.microsoftvirtualacademy.com/ | |
Tudo sobre AngularJS - Rodrigo Branas | |
https://www.youtube.com/playlist?list=PLQCmSnNFVYnTD5p2fR4EXmtlR6jQJMbPb | |
Desvendando a linguagem JavaScript - Rodrigo Branas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--O campo do TYPE armazena o tipo do objeto a ser localizado, onde : | |
--U => Tabela Usuário, S => Tabela de sistema, P => Procedure, V => View, F => Function | |
SELECT A.NAME, A.TYPE, B.TEXT | |
FROM SYSOBJECTS A (nolock) | |
JOIN SYSCOMMENTS B (nolock) | |
ON A.ID = B.ID | |
WHERE B.TEXT LIKE '%SELECT DISTINCT%' --- Informação a ser procurada no corpo da procedure, funcao ou view | |
AND A.TYPE = 'P' --- Tipo de objeto a ser localizado no caso procedure | |
ORDER BY A.NAME |