如何使用TSQL创建一个简单的两个表模式



我正在尝试创建一个带有两个表的模式,然后将稍后查询/添加数据。我正在使用stackexchange数据资源管理器" t-sql":https://data.stackexchange.com/stackoverflow/query/new

这是要求:

客户表:

    unique account id, 
    Fname
    Lname 
    create date

customerstatus 表(status会说待处理,活动或取消(:

    unique record id
    unique account id 
    string value named Status, 
    create date

其他要求:

  • 表包含主键
  • 自动递增标识符
  • 指示不应为null的列
  • 具有适当的列数据类型

这是我到目前为止所拥有的:

CREATE TABLE CUSTOMERS
(
   ID INT NOT NULL,
   FNAME VARCHAR (20) NOT NULL,
   LNAME VARCHAR (20) NOT NULL,
)
CREATE TABLE CustomerStatus
(
   recordID INT NOT NULL,
   ID INT NOT NULL,
   STATUS VARCHAR (10) NOT NULL,
)

您无法在Data Explorer上执行此操作。

尝试rextester.com或dbfiddle.uk。

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

create table Customers(
   id int not null identity(1,1) primary key,
   fname varchar (20) not null,
   lname varchar (20) not null,
);
create table CustomerStatus(
   recordid int not null identity(1,1),
   id int not null references Customers(id),
   [status] varchar (10) not null,
);

最新更新