Posted on

auto-generate INSERT statements for a SQL Server table

  1. Right-click on the database and go to Tasks > Generate Scripts.
  2. Select the tables that you want to generate the script.
  3. Go to Set scripting options tab and click on the Advanced button.
  4. In the General category, go to Type of data to script
  5. There are 3 options: Schema OnlyData Only, and Schema and Data. Select the appropriate option and click on OK.

Posted on

SQLSERVER – Backup on mapped drive

Scenario

You ar trying to backup a sqlserver db on mapped network drive. You have already mapped the drive in Windows and you can see that drive in Windows Explorer. You are not able to see the drive which is mapped when you open the backup procedure using SqlServer Managment studio.

Solution

First of all you not need the previous mapped network drive created by Explorer. You have to create this drive using SqlServer, and you’ll not be able to see it using Exploer.

Enable xp_cmdshell

You need to execute below to enable xp_cmdshell as its disabled by default due to security reasons. (Please turn off again once you done with the work)

Using SSMS execute thesse commands :

EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'xp_cmdshell',1
GO
RECONFIGURE
GO

After this you ‘ll have a positive reaction a this command that using SSMS you should use for testing previous operations :

EXEC XP_CMDSHELL 'Dir C:'

Map Network Drive

To map network drive you have to use the same command that you should use over Windows ysig command prompt :

'net use Z: \\networkShare\Test'

So, using SSMS you have to run the command

EXEC XP_CMDSHELL 'net use Z: \\networkShare\Test'

Now you should test this connection with the command

EXEC XP_CMDSHELL 'Dir Z:'

but, the most important goal, is tha you’ll be able to see teh drive Z during backup proceure over SSMS

Map Network Drive cmd – net use user password

The above command will work and completes successfully without asking the user to provide a username/password if the user has authorized access to this network share. If not, But the easy way is to use the “net use” command on the command prompt line explained above.

net use Z: \\networkShare\Test /u:domainname\username password

So, using SSMS you have to run the command

EXEC XP_CMDSHELL 'net use Z: \\networkShare\Test /u:domainname\username password'
Posted on

Spostare un database mysql – mariadb da un server windows ad un altro server windows

Installare xampp sul nuovo server.

Se acceso, spegnere mysql.

Nella cartella C:\xampp\mysql\data creare una nuova cartella, per esempio con il nome del database che state spostando.

Copiare in essa tutti i file dati (.frm, .ibd, .myd, .myi) dalla relativa cartella del vecchio server.

Copiare dal vecchio server nella stessa posizione del nuovo server, cioè nella cartella C:\xampp\mysql\data i file ib_logfile0, ib_logfile1, ibdata1

ate partire mysql. Aprite un prompt di dos, andate nella catella

cd C:\xampp\mysql\bin

mysql -u root -p

show databases;

Dovreste vedere il nuovo database aggiunto ai precedenti.

Aprire un altro prompt di dos e fate un check delle tabelle con i comandi

cd C:\xampp\mysql\bin

mysqlcheck -uroot -p VOSTRODATABASE

Aprite il browser e collegatevi a phpmyadmin con http://localhost/phpmyadmin

Dovreste vedere il database e le tabelle.

Posted on

Apertura di un file csv in Excel. Come mantenere tutti gli zero iniziali nei campi

Quando aprite un file csv in Excel, se avete dei dati che contengono lo zero (0) all’inizio, questi saranno trasformati in numeri perdendo lo zero iniziale. Un caso tutto Italiano è quando avete un file csv che contiene i numeri di partita iva di una serie di aziende. Vediamo come fare per non perdere gli zero iniziali.

Non aprite il file csv con Excel. Aprite invece Excel con un nuovo foglio. Andate nella tab “Dati” e spingete “da testo/csv”.

Caricate ora il vostro file csv. Compare una nuova finestra che esegue una trasformazione dei dati.

In alto avete alcune scelte importanti.

Excel ha capito quale è il delimitatore del file csv. Nota : usate questa procedura anche quando state importando dei dati salvati in un file csv con un delimitatore differente dal vostro standard.

Excel cerca di capire il tipo di dati per ciascuna colonna “in base alle prime 200 righe”; vi consiglio di selezionare “in base all’intero set di dati”. In questo modo Excel dovrebbe capire che la colonna con gli zeri contiene del testo e non dei numeri. Spingete “Carica” per terminare la procedura o “Trasforma Dati” per forzare eventualmente altre scelte.

 

Posted on

installing sqlserver 2008: Performance counter registry hive consistency check failed

if, during installation of Sql Server 2008 you have this error : Performance counter registry hive consistency check failed

First try

Open a command prompt with administrator user rights (Run as Administrator)

cd c;/windows/system32
lodctr /R:PerfStringBackup.INI

Restart the system and try again to install sqlserver

Second attempt

Open a command prompt with administrator user rights (Run as Administrator). Lunch install without that feature

C:\MyFolder\SQLEXPR_x86.exe /ACTION=install /SKIPRULES=PerfMonCounterNotCorruptedCheck
Posted on Lascia un commento

Sql Server 2014, Integration Services e Oracle

SSIS e SSDT su SQL SERVER 2014

SSIS non è presente su Sql Server 2014. Per creare pacchetti di Integration Service dovete scaricare ed installare  SQL Server Data Tools (SSDT).

Download SSDT

Utilizzerete tale tool anche per Convertire i pacchetti SSIS creati con Sql Server 2008 nel nuovo formato di progetto.

Connessione ad Oracle da SSDT su SQL SERVER 2014

Per connettervi ad Oracle attraverso ADO.NET nell’ambiente SSDT dovete installare un client di Oracle. Sicuramente state lavorando su una macchina a 64 bit. Dovete scaricare il client a 32 bit e installarlo scegliendo il tipo di installazione “Amministrativa”.

 

Posted on

le istruzioni sql che non ricordo mai (ms sql server)

Creazione di una tabella partendo da una tabella – Copia

SELECT * INTO NEWTABLE FROM OLDTABLE


Accodamento di righe da una tabella ad un altra

INSERT INTO DESTINATIONTABLE SELECT * FROM ORIGINTABLE


Sostituzione di una stringa all’interno di una stringa

UPDATE MYTABLE SET MYFIELD = REPLACE(MYFIELD,’oldstring’,’newstring’) WHERE …….


Quale versione di SqlServer sto usando ?

SELECT SERVERPROPERTY(‘productversion’), SERVERPROPERTY (‘productlevel’),SERVERPROPERTY (‘edition’)


Quando è stata creata (o modificata) una tabella ?

SELECT name, create_date, modify_date FROM MYDB.sys.tables order by create_date desc


Trova il numero dei record di ogni tabella

SELECT sc.name +’.’+ ta.name TableName
,SUM(pa.rows) RowCnt
FROM sys.tables ta
INNER JOIN sys.partitions pa
ON pa.OBJECT_ID = ta.OBJECT_ID
INNER JOIN sys.schemas sc
ON ta.schema_id = sc.schema_id
WHERE ta.is_ms_shipped = 0 AND pa.index_id IN (1,0)
GROUP BY sc.name,ta.name
ORDER BY SUM(pa.rows) DESC


Problema Recovery Pending

Controllo stato del database

SELECT name, state_desc from sys.databases

Portare online il databse

ALTER DATABASE databsename SET ONLINE

Controllo errori sul database

DBCC CHECKDB(‘databsename’) WITH NO_INFOMSGS


Controlla se nel database è installata la ricerca full-text

SELECT
CASE
WHEN
FULLTEXTSERVICEPROPERTY(‘IsFullTextInstalled’) = 1
THEN
‘INSTALLED’
ELSE
‘NOT INSTALLED’
END IsFullTextInstalled

Posted on Lascia un commento

ORACLE E TERMINAL SERVER

Quando create un nuovo database Oracle potreste incappare nell’errore ORA-12560: TNS:protocol adapter error. Se avete fatto tutti i controlli del caso (per esempio il SID o il servizio di Oracle) e non avete trovato la soluzione, probabilmente è perchè state creando il database collegati in terminal server. Dovete farlo dalla console fisica (o virtuale).