Tags » SQLSERVER

SQLServer - unattended installation

I didn’t quite get to the end of doing this as YouTube video, so for now a summary:

Provided you have a correctly configured ConfigurationFile.ini, whose purpose is to supply all the required configuration points for a SQLServer installation (works for 2008,2012,2014, with minor differences), then you can execute a command line very similar to this, and after about 30 minutes, you have a full SQLServer installation (plus RS, IS, etc, depending on what you have included in the config file): 177 more words

SQLServer

How to check if a CURSOR exists

IF SELECT CURSOR_STATUS('global','myCursor')>=-1
BEGIN
DEALLOCATE myCursor
END

SQLServer

SQLServer – Como reorganizar todos los indices de una tabla

USE [NOMBREDB];
GO

ALTER INDEX ALL ON [NombreEsquema].[NombreTabla]
REORGANIZE ;
GO

Probado en: SQLServer 2008 R2

SQLServer

Query cursor and fetching rows - Allow SELECT only on some tables

Here a nice sql to generate a sql string using cursors.


DECLARE @nomeS nvarchar(50)
DECLARE @nomeT nvarchar(50)

DECLARE aQUERY CURSOR FOR
select s.name, o.name
from sys.objects o
join sys.schemas s on o.schema_id = s.schema_id
where o.type = 'U' and s.name = 'dbo' and ((o.name Like 'CG%') Or (o.name Like 'TB%'))

BEGIN TRAN T1
OPEN aQUERY

FETCH NEXT FROM aQUERY INTO @nomeS, @nomeT
  /* While the end of the result set has not been reached */

WHILE @@FETCH_STATUS <> -1
   BEGIN
      /* If the row was not deleted after the cursor was opened */
      IF @@FETCH_STATUS <> -2
        BEGIN
		PRINT 'GRANT SELECT ON ' + @nomeS + '.' + @nomeT + ' TO reader01' + Char(10) + 'GO'
        END
	FETCH NEXT FROM aQUERY INTO @nomeS, @nomeT
    END
COMMIT TRAN T1
CLOSE aQUERY
DEALLOCATE aQUERY

Padding Fields for Fixed-Position Data Formats

Fixed-position data formats will seemingly be with us forever. Despite the relative ease of parsing CSV (or other delimited formats), or even XML, many data exchanges require a fixed-position input. 582 more words

Sqlserver

How to join multiple rows into a single column in TSQL

Problem

Sometimes, when We use T-SQL (TransactSQL) to query data, We need concatenate a column from multiple rows into a single column.

An example… 67 more words

Database