SQL Server:在所有数据库表中删除所有“非空”约束

问题描述

如何使用sql Server在所有表的所有列中删除所有非空约束?

想循环在所有表和列中运行此查询How to remove not null constraint in sql server using query

注意:要求适用于所有非主键列。

类似的问题:

How to drop all Foreign Key constraints in all tables?

解决方法

您可以使用以下查询为每一列生成alter语句。 并使用生成的语句来更改表。 这不会更改主键列,但不会考虑其他外键约束。

RetryPolicy policy = new DefaultRetryPolicy(1500,1,DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
request.setRetryPolicy(policy);


// solution [
int maxTimeOut = 15000;

new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
        queue.stop();
    }
},maxTimeOut);
// solution]

queue.add(stringRequest);