/* 创建表 及设置 主键 */ CREATE TABLE TABLE_USER ( USER_ID INT IDENTITY(1,1) NOT NULL, USER_NAME NVARCHAR(40) NOT NULL, LAST_UPDATED_BY NVARCHAR(15), LAST_UPDATED_DATE DATETIME, CONSTRAINT USER_PK PRIMARY KEY (USER_ID) ); /*ALTER TABLE 增加多个字段 */ ALTER TABLE TABLE_USER ADD DEPARTMENT_ID INT NOT NULL ,COMPANY_ID INT NOT NULL ,TEMP_COL NVARCHAR(10) ; /*ALTER TABLE 增加多个外键 */ ALTER TABLE TABLE_USER ADD CONSTRAINT USER_DEPARTMENT_FK FOREIGN KEY(DEPARTMENT_ID) REFERENCES TABLE_DEPARTMENT(DEPARTMENT_ID) ,CONSTRAINT USER_COMPANY_FK FOREIGN KEY(COMPANY_ID) REFERENCES TABLE_COMPANY(COMPANY_ID) ; /*ALTER TABLE 删除字段 */ ALTER TABLE TABLE_USER DROP COLUMN TEMP_COL;