Friday, 24 November 2023

SQL

 When updating one column with another based on a condition, you generally don't need to use constraints. Constraints are more related to ensuring data integrity and maintaining relationships between tables. However, if you want to ensure that the values you are updating meet certain conditions, you can use a combination of the CHECK constraint and the WHERE clause in the UPDATE statement.

Here's an example:

-- Add a CHECK constraint to ensure that salary is not negative ALTER TABLE employees ADD CONSTRAINT CHK_Salary_NonNegative CHECK (salary >= 0); -- Update bonus based on a condition UPDATE employees SET bonus = salary WHERE salary > 50000;



In this example, a CHECK constraint is added to ensure that the salary column does not contain negative values. The UPDATE statement then updates the bonus column for rows where the salary is greater than 50000.

Remember, it's important to ensure that your data meets the conditions you are setting, and constraints can help with that. Always make sure to test your updates on a small set of data first, and consider creating a backup before making significant changes to your database.

Get List of sps based on table name..

SELECT Name FROM sys.procedures WHERE OBJECT_DEFINITION(OBJECT_ID) LIKE '%profiles%'


Wednesday, 22 November 2023

Get List of procedures create based on date

 Get List of procedures create based on date.


select name,create_date,modify_date

from sys.procedures

order by modify_date desc

Wednesday, 15 November 2023

main class imp

main response call for all api response......   

public class ResponseDto

    {
        public object? Result { getset; }
        public bool IsSuccess { getset; } = true;
        public string Message { getset; } = "";
        public string Status { getset; }
        public int ID { getset; } = 0;
    }

Thursday, 9 November 2023

SQL TIPS

 https://youtube.com/shorts/4inEkbE9_gU?si=SzsfYetzcRJwl6EE


Wednesday, 8 November 2023

Triggers...(imp)

 Create Triggers on Table

> the main use to if i deleted or inserted new record on table then customer ask old data which one deleted

to prevent from this type of issues i am creating the histroy schema with same table then.

1.creating the table on history schema same as main table

2.create trigger on main table.


-- ==============================================

-- Create dml trigger template Azure SQL Database 

-- ==============================================

-- Drop the dml trigger if it already exists



CREATE TRIGGER [dbo].[tr_Returntoemp_Delete] ON [dbo].[tbl_ReturnToEmployeeDetails]

   INSTEAD OF DELETE

AS 

BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from

-- interfering with SELECT statements.

SET NOCOUNT ON;

    -- Insert statements for trigger here

INSERT INTO [History].[tbl_ReturnToEmployeeDetails]

SELECT GETDATE(), RT.ID,RT.ManagerID,RT.EmployeeID,RT.ActionerID,RT.AppraisalTypeID,

RT.Description,RT.ModifiedBy,RT.ModifiedOn,RT.IsActive

FROM [tbl_ReturnToEmployeeDetails] as RT

INNER JOIN DELETED ON RT.ID=Deleted.ID


DELETE FROM tbl_ReturnToEmployeeDetails WHERE ID IN(SELECT ID FROM Deleted)  



END

GO

ALTER TABLE [dbo].[tbl_ReturnToEmployeeDetails] ENABLE TRIGGER tr_Returntoemp_Delete

GO

-- ==============================================

-- ==============================================

7 Common mistakes in Dot Net — You can avoid

  There are many common mistakes made during .NET (ASP.NET, .NET Core) development, which affect performance, security, and code… Code Crack...