将列更改为外键

时间:2015-06-29 07:07:41

标签: sql sql-server

如何将现有列从bit更改为外键(int)?

例如,列NEW_B的创建方式如下:

ALTER TABLE [dbo].[APPLICATION]
ADD [NEW_B] [bit] NULL
GO

但现在我希望NEW_B引用表ID的列ATTACHMENT(int)(希望保留名称NEW_B,同时允许NULLs )。

1 个答案:

答案 0 :(得分:2)

以下是语法:

{-# LANGUAGE OverloadedStrings #-}

module Bar where

import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as BS

import Control.Monad
import Control.Applicative
import Control.Monad.Trans.Except 
import Data.Monoid

check1 str =
  if str == "abc"
    then return 1
    else throwE ["not equal to abc" ]

check2 str =
  if str == "def"
    then return 2
    else throwE ["not equal to def" ]

checks str = check1 str <|> check2 str <|> throwE ["not abc or def"]

main :: IO ()
main = do
  input <- BS.getLine
  case runExcept $ checks input of
    Left e  -> mapM_ (BS.putStrLn . ("Error: " <>)) e 
    Right a -> print a