2

我想从表“ProjectTable”创建一个表“客户”:

CREATE TABLE Customer AS
    (
        SELECT CustCompanyName, CustContactName, CustContactTitle, CustAddress, CustCity, CustRegion, CustPostalCode, CustCountry, CustPhone, CustFax FROM ProjectTable
    );

而且我需要在这里添加更多内容,因为附加列“id”将是主键列,或者“客户”将是对另一个表列的引用。怎么做?

4

1 回答 1

1

您可以使用与 ProjectTable 相同的表结构和相同的数据创建新表,然后您可以添加所需的其他字段:

SELECT CustCompanyName, CustContactName, CustContactTitle, CustAddress, CustCity, CustRegion, 
CustPostalCode, CustCountry, CustPhone, CustFax INTO Customer FROM ProjectTable

ALTER TABLE Customer ADD ID INT IDENTITY(1,1) PRIMARY KEY

ALTER TABLE Customer ADD customer VARCHAR(10)

ALTER TABLE Customer ADD CONSTRAINT Customer_customer_FK FOREIGN KEY ( customer ) REFERENCES MyOtherTable(PKColumn)
于 2012-12-02T21:13:25.157 回答