if this is an existing table with nulls in the my_id column then you have to update the column to remove the nulls first
CREATE TABLE my_details ( my_id varchar(50) NULL )
GO
INSERT INTO dbo.my_details ( my_id ) VALUES (NULL )
GO
ALTER TABLE my_details
ALTER COLUMN my_id varchar(50) NOT NULL;
GO
Gives you this error
Msg 515, Level 16, State 2, Line 9 Cannot insert the value NULL into
column 'my_id', table 'xStuff.dbo.my_details'; column does not allow
nulls. UPDATE fails.
trying to add a primary key gives you this
ALTER TABLE my_details
ADD PRIMARY KEY (my_id);
GO
Msg 8111, Level 16, State 1, Line 16 Cannot define PRIMARY KEY
constraint on nullable column in table 'my_details'. Msg 1750, Level
16, State 0, Line 16 Could not create constraint. See previous errors.
However
place an update in between and this change works
CREATE TABLE my_details ( my_id varchar(50) NULL );
GO
INSERT INTO dbo.my_details ( my_id ) VALUES (NULL );
GO
UPDATE dbo.my_details SET my_id = '' WHERE my_id IS NULL;
GO
ALTER TABLE my_details
ALTER COLUMN my_id varchar(50) NOT NULL;
GO
ALTER TABLE my_details
ADD PRIMARY KEY (my_id);
GO