【问题标题】:SQL Server 2012 Can't create any table [closed]SQL Server 2012 无法创建任何表 [关闭]
【发布时间】:2014-11-12 13:53:23
【问题描述】:

我无法在 SQL Server 中创建任何表。错误字段总是说,我的表名附近有问题。

有人可以从第一个表中查看我的语法吗?

create table course
(c_id int not null AUTO_INCREMENT, 
 r_id int not null AUTO_INCREMENT,
 start date,    
 end date,
 name varchar(20),
 leader int,
 constraint pk_cousrse primary key (k_id, r_id, leader)

 );
insert into course (start, end, name, leader)
values (26.03.2012, 23.05.2013, , morrison);

【问题讨论】:

  • 让我们克服你想要在你的表上的 2 个标识列的事实,你的插入也没有意义。对于初学者,您有一个leader 列,它是一个INT,但您想在其中插入morrison。您也没有考虑到您需要对字符串使用单引号(并且您还需要将日期括在单引号中)

标签: sql sql-server-2012


【解决方案1】:

是的,错误的部分是AUTO_INCREMENT。 SQL Server 中没有AUTO_INCREMENT。应该是IDENTITY

再次,您尝试在表中创建两个IDENTITY 字段。这是不允许的。您只能有一个 IDENTITY 字段。

startend 是保留字。您需要使用[](方括号)转义它们

你的CREATE 语句应该是这样的

create table course (c_id int not null IDENTITY, r_id int not null , 
[start] date,
[end] date, 
name varchar(20), 
leader int, 
constraint pk_cousrse primary key (c_id, r_id, leader)
)

【讨论】:

  • 嘿,非常感谢,现在我可以创建我的第一张桌子了! :) 即使我的插入命令似乎仍然不起作用。似乎日期有问题:插入课程 ([start], [end], name, leader) 值 (26.03.2012, 23.05.2013, 'c' , 'morrison');
  • @FelixBeer,你需要像insert into course ([start], [end], name, leader) values ('26.03.2012', '23.05.2013', 'c' , 'morrison');这样引用日期
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-28
  • 1970-01-01
  • 2023-03-09
  • 2013-08-23
  • 2017-06-15
  • 1970-01-01
  • 2022-01-27
相关资源
最近更新 更多