Author: Shameer
•8:54 PM
Open Microsoft SQL Server -> Enterprise Manager

Click here for larger image


Click here for larger image

Right Click and Select New SQL Server Registration

Click here for larger image

Click Next.
Click here for larger image

Enter the Servername and click Add button

Click here for larger image


Then Click Next button

Click here for larger image


Again Click Next

Click here for larger image

Click Next


Click here for larger image


Click Finish

Click here for larger image


Once the server is connect click Close

Click here for larger image


Click here for larger image

Now the server is connected and it will list the database. Select the corresponding database.

Click here for larger image



Click here for larger image

Click Stored Procedure from the Tree

Click here for larger image


Select all the procedure in the right side grid using Ctrl + A

Click here for larger image

Now right click select All Tasks -> Generate SQL Script and click Ok


Click here for larger image
Give a name for the script and select the path to Save

Click here for larger image

Progressing

Click here for larger image

Now the script is saved successfully

Click here for larger image

Now we can view the script from the My Documents folder where we saved initially
Author: Shameer
•9:46 PM

How to change security authentication mode

  1. In SQL Server Management Studio Object Explorer, right-click the server, and then click Properties.
  2. On the Security page, under Server authentication, select the new server authentication mode, and then click OK.
  3. In the SQL Server Management Studio dialog box, click OK to acknowledge the requirement to restart SQL Server.
  4. In Object Explorer, right-click your server, and then click Restart. If SQL Server Agent is running, it must also be restarted.

To enable the sa login

  1. In Object Explorer, expand Security, expand Logins, right-click sa, and then click Properties.
  2. On the General page, you might have to create and confirm a password for the login.
  3. On the Status page, in the Login section, click Enabled, and then click OK.

Using Transact - SQL

To enable the sa login
  1. In Object Explorer, connect to an instance of Database Engine.
  2. On the Standard bar, click New Query.
  3. Copy and paste the following example into the query window and click Execute. The following example enables the sa login and sets a new password.
    ALTER LOGIN sa ENABLE ;
    GO
    ALTER LOGIN sa WITH PASSWORD = '<enterStrongPasswordHere>' ;
    GO
    
Author: Shameer
•3:12 AM


Click here for larger image





Click here for larger image

Click here for larger image


Click here for larger image


Click here for larger image


Click here for larger image


Click here for larger image


Click here for larger image


Click here for larger image


Click here for larger image


Click here for larger image


Author: Shameer
•2:17 AM

Input Data



Query to display the duplicate values from the table
---------------------------------------------------


SELECT a.* FROM dbo.dept As [a]
 INNER JOIN
  (
      SELECT dept_name, mgr_name FROM   dbo.dept
    GROUP BY dept_name, mgr_name
      HAVING Count(*)  >1
  ) As [b]
    ON a.dept_name = b.dept_name
   AND a.mgr_name  = b.mgr_name


Output
---------



Query to delete the duplicate values from the table
--------------------------------------------------------

 DELETE FROM dbo.dept
   WHERE dbo.dept.dept_id IN

-- List 1 - all rows that have duplicates
 (SELECT T1.dept_id
    FROM dbo.dept AS T1
   WHERE Exists (SELECT dept_name, mgr_name, Count(dept_id)
    FROM dbo.dept
   WHERE dbo.dept.dept_name = T1.dept_name
     AND dbo.dept.mgr_name = T1.mgr_name
GROUP BY dbo.dept.dept_name, dbo.dept.mgr_name
  HAVING Count(dbo.dept.dept_id) > 1))
     AND dbo.dept.dept_id NOT IN

-- List 2 - one row from each set of duplicate
 (SELECT Min(dept_id)
    FROM dbo.dept AS T1
   WHERE Exists (SELECT dept_name, mgr_name, Count(dept_id)
    FROM dbo.dept 
   WHERE dbo.dept.dept_name = T1.dept_name
     AND dbo.dept.mgr_name = T1.mgr_name
GROUP BY dbo.dept.dept_name, dbo.dept.mgr_name
  HAVING Count(dbo.dept.dept_id) > 1)
GROUP BY dept_name, mgr_name)


Output
----------