我收到了一个sql代码:
create table dbo.Dokumendid(
id int identity not Null primary key,
idPersonal int not Null references dbo.Personal on delete cascade,
Liik char(1) Not Null, -- Liik: L - lepingud, K - koolitused, T - tervisetõendid
FailiNimetus nvarchar(200) not null, -- faili nimetus
LaadimiseKpv smalldatetime null, -- laadimise kpv
Fail varbinary(max) null, -- fail
Markus nvarchar(max) Null, -- märkus
dtCreated datetime default GetDate() Null,
UserNameCreated nvarchar(50) null,
dtUpdated datetime null,
UserNameUpdated nvarchar(50) null
)
Go
create index IX_Personal on dbo.Dokumendid(idPersonal) on INDEXES
Go
但是我们已经有了表dbo.Dokumendid,所以当我将create改为alter时,我会得到错误:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near '('.
Msg 102, Level 15, State 1, Line 15
Incorrect syntax near '('.
我将其更改为: alter table dbo.Dokumendid alter column error:
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'identity'.
Msg 102, Level 15, State 1, Line 15
Incorrect syntax near '('.
发布于 2020-04-30 07:10:42
如果要添加内联外键:
create table dbo.Dokumendid(
id int identity not Null primary key,
idPersonal int not Null, --references dbo.Personal on delete cascade,
Liik char(1) Not Null, -- Liik: L - lepingud, K - koolitused, T - tervisetõendid
FailiNimetus nvarchar(200) not null, -- faili nimetus
LaadimiseKpv smalldatetime null, -- laadimise kpv
Fail varbinary(max) null, -- fail
Markus nvarchar(max) Null, -- märkus
dtCreated datetime default GetDate() Null,
UserNameCreated nvarchar(50) null,
dtUpdated datetime null,
UserNameUpdated nvarchar(50) null,
CONSTRAINT FK_Dokumendid_idPersonal FOREIGN KEY (idPersonal) REFERENCES dbo.Personal (idPersonal) on delete cascade
)
Go
此外,您还可以在线添加索引创建(来自SQL Server 2014):
create table dbo.Dokumendid(
id int identity not Null primary key,
...
CONSTRAINT FK_Dokumendid_idPersonal FOREIGN KEY (idPersonal) REFERENCES dbo.Personal (idPersonal) on delete cascade,
index IX_Personal(idPersonal)
)
Go
https://stackoverflow.com/questions/61517548
复制