CentOS 7 | Yum update – recovery database
mv /var/lib/rpm/__db* /tmp/ rpm --rebuilddb yum clean all
MYSQL | Disabilitare i log
Connettersi al db con l’utente root e lanciare il seguente comando: SET GLOBAL general_log = ‘OFF’; Riavviare il servizio
SQL SERVER | Cancellare tutte le tabelle di un database
DECLARE @tableSchema VARCHAR(5) = 'dbo' DECLARE @dbName VARCHAR(50) = 'TEST' SELECT CONCAT('USE ') AS Obj2Drop UNION SELECT CONCAT('DROP TABLE ') AS Obj2Drop ---TABLES--- FROM information_schema.tables WHERE TABLE_SCHEMA = @tableSchema AND…
SQL SERVER | If Exists nelle versioni 2008 e 2008R2
---SQL Server 2008--- IF OBJECT_ID(N'.', N'P') IS NOT NULL DROP PROCEDURE . GO ---SQL Server 2008 R2--- IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID('.') AND type in…
SQL SERVER | Modificare il nome logico del database
USE MASTER GO ALTER DATABASE DatabaseName MODIFY FILE (NAME = 'LogicalName_Data', NEWNAME='NEWLogicalName_Data') GO ALTER DATABASE DatabaseName MODIFY FILE (NAME = 'LogicalName_Log', NEWNAME='NEWLogicalName_Log') GO
SQL SERVER | Chiudere tutte le connessioni attive
ALTER DATABASE 'NomeDatabase' SET SINGLE_USER WITH ROLLBACK IMMEDIATE; ALTER DATABASE 'NomeDatabase' SET MULTI_USER WITH ROLLBACK IMMEDIATE;
SQL SERVER | Elencare i file presenti in una cartella
EXEC sp_configure 'show advanced options', 1 GO RECONFIGURE GO EXEC sp_configure 'xp_cmdshell', 1 GO RECONFIGURE GO DECLARE @Command VARCHAR(1000) SET @Command = 'dir c:\*.txt /b /s' DECLARE @FilesInAFolder TABLE (FileNamesWithFolder…
SQL SERVER | Elencare le tabelle e le viste presenti nel database
SELECT Name, CASE WHEN Type = 'U' THEN 'Table' ELSE 'View' END AS 'Type', Create_Date, Modify_Date FROM SYS.OBJECTS WHERE TYPE IN (N'U', N'V') ORDER BY Name ASC
SQL SERVER | Elencare le colonne presenti in una tabella
SELECT co.Column_Name AS 'Name' ,co.Data_Type AS 'Type' ,ISNULL(co.Character_Maximum_Length, 0) AS 'Lenght' ,CASE WHEN co.Data_Type='Bit' AND NOT co.Column_Default IS NULL THEN CASE WHEN REPLACE(REPLACE(REPLACE(ISNULL(co.Column_Default,''),'(',''),')',''),'''','') = 0 THEN 'False' ELSE 'True' END…