0

I have a PostgreSql DB connected to Visual Studio. I want to change a column(what column I want) from null to not null via Visual Studio. How I can do that? Can't find this on internet.

2

1 Answer 1

1

Try this code:

SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;

cmd.CommandText = "ALTER TABLE YourTableName ALTER COLUMN YourColumnName DROP NOT NULL;";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;

sqlConnection1.Open();

reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.

sqlConnection1.Close();
Sign up to request clarification or add additional context in comments.

1 Comment

Where I should put that?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.