2017-04-24 121 views
0

我想创建一个有两个表的模式,并且稍后会向他们查询/添加数据。我现在用的是StackExchange数据资源管理器 “T-SQL”:http://data.stackexchange.com/stackoverflow/query/new如何使用TSQL创建一个简单的两表模式?

这里是要求:

客户表:

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

什么是你的问题? –

+0

如何创建两个表模式。底部是我到目前为止。 – MarkM

+0

我不明白你的问题。你显然有表 - 或者至少是'create table'语句。 –

回答

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, 
); 
相关问题