Pages

Wednesday, May 29, 2013

AD commands

Get user by display name
http://technet.microsoft.com/en-us/library/cc754525(v=ws.10).aspx


  • DSQUERY USER -name "Wahib, Refky"
  • DSQUERY USER -name "W*"
  • DSQUERY group  -name "PS_NSW - Learning_and_Business_Systems - LS"




Monday, May 20, 2013

Useful scripts for database migration




 DECLARE @name nvarchar(50);
   DECLARE tableCursor CURSOR FOR
       SELECT name
FROM sys.Tables

  OPEN tableCursor

  FETCH NEXT FROM tableCursor into @name

  WHILE @@FETCH_STATUS = 0
  BEGIN
 
 

         PRINT @name

     --exec( 'drop table ['+@name+']');

        exec( 'select top 1000 * from  "'+@name+'"');

    FETCH NEXT FROM tableCursor into @name

  end  
  CLOSE tableCursor;
  DEALLOCATE tableCursor;
  go

Tuesday, May 7, 2013

Cursor, drop all tables,views, procedures



USE LRRV6Portal
GO



--SELECT name
--FROM sys.Tables
--GO




  DECLARE @name nvarchar(50); 
   DECLARE tableCursor CURSOR FOR
       SELECT name
FROM sys.Tables
 
  OPEN tableCursor
 
  FETCH NEXT FROM tableCursor into @name
 
  WHILE @@FETCH_STATUS = 0
  BEGIN
  
  
 
         PRINT @name
        
        exec( 'drop table "'+@name+'"');

    FETCH NEXT FROM tableCursor into @name

  end   
  CLOSE tableCursor;
  DEALLOCATE tableCursor;
  go

------------

 DECLARE @name nvarchar(50);
   DECLARE viewCursor CURSOR FOR
       SELECT name
FROM sys.views

  OPEN viewCursor

  FETCH NEXT FROM viewCursor into @name

  WHILE @@FETCH_STATUS = 0
  BEGIN
 
 

         PRINT @name
       
        exec( 'drop view "'+@name+'"');

    FETCH NEXT FROM viewCursor into @name

  end  
  CLOSE viewCursor;
  DEALLOCATE viewCursor;
  go

----------

 DECLARE @name nvarchar(50);
   DECLARE procedCursor CURSOR FOR
       SELECT name
FROM sys.procedures

  OPEN procedCursor

  FETCH NEXT FROM procedCursor into @name

  WHILE @@FETCH_STATUS = 0
  BEGIN
 
 

         PRINT @name
       
        exec( 'drop procedure "'+@name+'"');

    FETCH NEXT FROM procedCursor into @name

  end  
  CLOSE procedCursor;
  DEALLOCATE procedCursor;
  go