Wednesday, March 5, 2014

Formates Data Objects


--Cursor
Declare MyCursor CURSOR FOR    
select Categoryid,subcategoryid,subsubcategoryid from #temp    
OPEN MyCursor    
     
FETCH NEXT FROM MyCursor    
INTO @QCategoryid, @QSubcategoryId, @QSubSubcategoryId    
     
WHILE @@FETCH_STATUS = 0    
BEGIN
-- for Work
 
FETCH NEXT FROM MyCursor    
INTO @QCategoryid, @QSubcategoryId, @QSubSubcategoryId    
END    
CLOSE MyCursor    
DEALLOCATE MyCursor

--Function

CREATE FUNCTION [dbo].[AllSubCategory](@ProductId bigint )
RETURNS varchar(8000)
AS
BEGIN
declare @return varchar(8000)
 RETURN @return
END

--View
CrEATE view [dbo].[vw_rptBlog]
as
SELECT *  from mlm_achiever


--Trigger

CREATE TRIGGER reminder2
ON Sales.Customer
AFTER INSERT, UPDATE, DELETE
AS
   EXEC msdb.dbo.sp_send_dbmail
        @profile_name = 'AdventureWorks2012 Administrator',
        @recipients = 'danw@Adventure-Works.com',
        @body = 'Don''t forget to print a report for the sales force.',
        @subject = 'Reminder';
GO

--Index
CREATE INDEX index_name
ON table_name (column_name,column_name,..)

CREATE CLUSTERED INDEX IX_TestTable_TestCol1
    ON dbo.TestTable (TestCol1);
----
CREATE UNIQUE INDEX index_name
on table_name (column_name);


No comments:

Post a Comment