What is Create & Alter in SQL SERVER PART 1 With Example Code

Your SQL statements look mostly correct, but there's a small error in the first ALTER TABLE statement where you're trying to add a default constraint to the "Gender" column. It seems like you're missing the "Id" column name in the SELECT statement. Here are the corrected statements:





-- Add default constraint to existing column in the Student table
ALTER TABLE Student
ADD CONSTRAINT DF_Student_Gender
DEFAULT 1 FOR Gender;
 
-- Add new column with default constraint in the Student table
ALTER TABLE Student
ADD NewColumnName1 DataType1 NULL
CONSTRAINT DF_Student_NewColumn1 DEFAULT DefaultValue1;
 
-- Create another table
CREATE TABLE Course (
    CourseId INT PRIMARY KEY,
    CourseName NVARCHAR(max),
    Instructor NVARCHAR(max),
    StartDate datetime,
    EndDate datetime,
    IsActive BIT
);
 
-- Select specific columns from the Student table
SELECT [Id],
       [Name],
       [CreateDate],
       [UpdateDate],
       [IsDeleted],
       [IsActive],
       [EmailId],
       [Gender]
FROM [Student];