0
내가 널이 아닌 열을 정의하고 마지막 세 개의 열 (UTCInserted, UTCUpdated, & SRVNAME) 나는 기본 제약 조건을 만드는거야위한거야열에 기본 제약 조건이있는 경우 SQL Server 2012 열 가져 오기는 null 오류 일 수 없습니다.
create table dbo.dg_world_records(
WorldRecordId int not null identity(1,1)
, GameTypeId int not null
, PlayerId int not null
, NumberOfValues int not null
, TotalTime int not null
, DateOfRecord datetime not null
, GameId int not null
, UTCInserted datetime not null
, UTCUpdated datetime not null
, SrvName varchar(30) not null
)
go
alter table dg_world_records add constraint dg_world_records_worldrecordid_pk primary key (worldrecordid)
go
alter table dg_world_records add constraint dg_world_records_utcinserted_df default getutcdate() for utcinserted
go
alter table dg_world_records add constraint dg_world_records_utcupdated_df default getutcdate() for utcupdated
go
alter table dg_world_records add constraint dg_world_records_srvname_df default @@servername for srvname
go
... 다음 스키마를 고려하십시오.
저는 많은 시간을 회사 개발 서버에서 수행했으며 모든 것이 잘 작동합니다.
그러나 SQL Server 2012의 로컬 인스턴스에서 다음 삽입 문이 오류를 발생시킵니다. 여기
insert into dbo.dg_world_records(gametypeid, playerid, numberofvalues, totaltime, dateofrecord, gameid)
values(11, 1, 365, 430000, getdate(), -1)
오류 메시지입니다 ...
Msg 515, Level 16, State 2, Line 1
Cannot insert the value NULL into column 'SrvName', table 'dateguess.dbo.dg_world_records'; column does not allow nulls. INSERT fails.
The statement has been terminated.
내 생각 엔 당신이 null이 아닌 열 경우 디폴트 값을 지정하지 수 있도록 SQL Server의 환경 설정이 있다는 것입니다 제한이 정의됩니다.
감사합니다.
SrvName 열에 제약 조건이 있는지 100 % 확신합니까? 이 코드는 잘 작동합니다. –
테이블에 방아쇠가 있습니까? –
방금 SQL 2016 dev server라는 코드를 실행했고 작동했습니다. 내 코드를 실행하기 전에 테이블이 삭제 된 트리거가 없습니다. – codingguy3000