• This is Slide 1 Title

    This is slide 1 description. Go to Edit HTML and replace these sentences with your own words. This is a Blogger template by Lasantha - PremiumBloggerTemplates.com...

  • This is Slide 2 Title

    This is slide 2 description. Go to Edit HTML and replace these sentences with your own words. This is a Blogger template by Lasantha - PremiumBloggerTemplates.com...

  • This is Slide 3 Title

    This is slide 3 description. Go to Edit HTML and replace these sentences with your own words. This is a Blogger template by Lasantha - PremiumBloggerTemplates.com...

Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

Thursday, 30 January 2014

How to create Stored Procedure in MS SQL Server?

Syntex:
CREATE PROCEDURE [dbo].[sp_GetEmployee]
@EmpId INT,
@EmpName VARCHAR(50),
@DOB DATETIME,
@Error VARCHAR(MAX) OUT
AS
BEGIN
     SELECT a.EmpName, b.DeptName FROM tblEmployee a
          JOIN tblDept b ON b.EmpId=a.EmpId
          ORDER BY a.EmpName DESC

     IF @@error <> 0
          SET @Error = ERROR_MESSAGE()
END
Example:

MS SQL: ALTER

Syntex:
ALTER TABLE <table_name>
ADD <column_name> <datatype>
ALTER TABLE <table_name>
DROP COLUMN <column_name>
ALTER TABLE <table_name>
ALTER COLUMN <column_name> <datatype>
ALTER TABLE <table_name>
DROP COLUMN <column_name>
Example: