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

时间:2017-04-24 19:57:59

标签: sql sql-server tsql

我正在尝试使用两个表创建一个模式,稍后会向它们查询/添加数据。我正在使用StackExchange Data Explorer“T-SQL”:http://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

其他要求:

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

这是我到目前为止所做的:

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,
)

1 个答案:

答案 0 :(得分:0)

你不能在data explorer上这样做。

尝试rextester.comdbfiddle.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,
);