What is DROP & Insert in SQL SERVER PART 2 With Example Code

If you want to drop a constraint on a column, you first need to find out the name of the constraint. You can usually do this by querying the system tables or views that store information about constraints. For example


ALTER TABLE Student

DROP CONSTRAINT DF_Student_Gender;

 

ALTER TABLE [TABLE_NAME]

DROP CONSTRAINT [CONSTRAINT_NAME];

 

SELECT name

FROM sys.default_constraints

WHERE parent_object_id = OBJECT_ID('Student') AND type_desc = 'DEFAULT_CONSTRAINT';

 

 

-- Insert data into the Student table

INSERT INTO Student (Name, CreateDate, UpdateDate, IsDeleted, IsActive, EmailId, Gender)

VALUES ('A', '2024-04-14', '2024-04-14', 0, 1, 'A@example.com', 'Male');

 

-- Insert another row into the Student table

INSERT INTO Student (Name, CreateDate, UpdateDate, IsDeleted, IsActive, EmailId, Gender)

VALUES ('B', '2024-04-15', '2024-04-15', 0, 1, 'B@example.com', 'Female');