on primary(
name= 'PhotoServer',
filename='D:\文档\自己写的\编程\unity3d\PotoSever\PhotoServer.mdf',
size=5mb,
filegrowth=10%
)
log on(
name='PhotoServer_log',
filename='D:\文档\自己写的\编程\unity3d\PotoSever\PhotoServer.log',
size=1mb,
filegrowth=5%
)
use GameDB
create table Goods(
GoodsID int not null identity(1,1) primary key,
GoodsName nvarchar(10) default null,
GoodsType varchar(10) default null,
HP int default null,
Damage int default null,
)
insert into Goods values('血瓶','药',90,NULL),('剑','武器',NULL,10),('头盔','装备',NULL,NULL),('手腕',NULL,NULL,NULL),('大药瓶',NULL,NULL,NULL),('创口贴',NULL,40,NULL);
-----------------------------------------------
use GameDB
create table Users(
UserID int not null identity(1,1) primary key,
UserName nvarchar(15) not null unique,
UserPWD varchar(15) not null,
RigistedDate date default null,
)
insert into Users values('sikiedu2','123','2016-01-09'),('4','123',NULL),('3','er34',NULL),('sdf33','234',NULL),('sdfw324','34',NULL),('dewe','sdf',NULL),('wer2','we',NULL),('wer23','ewr',NULL),('wer','wer',NULL),('sdfwer','sdf3',NULL),('we234','234234',NULL);
-----------------------------------------------
use GameDB
create table Roles(
RolesID int not null identity(1,1) primary key,
RoleName nvarchar(10) not null unique,
RoleLevel int not null default 1,
RoleType nvarchar(10) not null default '战士',
UserID int not null,
foreign key (UserID)references Users(UserID),
)
insert into Roles values('天下无敌',1,'刺客',1),('天下无双',1,'坦克',1),('狄仁杰',1,'射手',2),('后裔',1,'射手',2),('武则天',1,'法师',5);
-----------------------------------------------
use GameDB
create table Inventory(
InventoryID int not null identity(1,1) primary key,
RoleID int default null,
GoodsID int default null,
Num int default null,
foreign key(GoodsID) references Goods(goodsID),
foreign key(RoleID) references Roles(RolesID),
)
insert into Inventory values(1,2,2),(2,3,3);
以上sql语句在执行到最后一句是总是会提示INSERT 语句与 FOREIGN KEY 约束"FK__Inventory__RoleI__2F10007B"冲突。而导致最后一个表无法插入数据,试了好多次都会出现同样的问题,sql server编辑器也没提示语句书写错误。。。。。。。。