MariaDB模式创建

时间:2018-07-01 22:54:37

标签: mariadb

我正在尝试在MariaDB中定义一组对象,即

scoreList.size()

但是我一直遇到的错误是

use SocialCartography;

drop table if exists Relationship;
drop table if exists Person;

create table if not exists Person (
    Id int unsigned not null auto_increment primary key,
    Name varchar(255) null, 
    DoB date null,
    DoD date null,
    PictureURL varchar(8192) null
);

create table if not exists Relationship (
    Id int unsigned not null auto_increment primary key,
    Since date null,
    Until date null,
    Type varchar(255),
    First int unsigned not null,
    Second int unsigned not null,
    PictureURL varchar(8192) null,

    constraint `fk_first_friend` 
    foreign key (first) references Person (Id)
        on delete cascade
        on update restrict,

    constraint `fk_second_friend` 
    foreign key (second) references Person (Id)
        on delete cascade
        on update restrict
);
go

delimiter //
create or replace procedure upsert_person (
    in pId int unsigned,
    in pName varchar(255),
    in pDoB date,
    in pDoD date,
    in pPictureURL varchar(8192)
)
as
begin
    if exists(select Id from Person where Id = pId) 
    then
        update Person
        set
            Name = pName,
            DoB = pDoB, 
            DoD = pDoD,
            PictureURL = pPictureURL
        where
            Id = pId;

        select pId as Id;
    else
        insert into Person
        (
            Name,
            DoB,
            DoD,
            PictureURL
        )
        values
        (p
            pName,
            pDoB,
            pDoD,
            pPictureURL
        );

        select last_insert_id() as Id;
    end if;
end //
delimiter ;

delimiter //
create or replace procedure delete_person (
    in pId int unsigned
)
begin
    delete Person
    where Id = pId;
end //
delimiter ;

delimiter //
create or replace procedure upsert_relationship ( 
    in pId int unsigned,
    in pSince date,
    in pUntil date,
    in pType nvarchar(255),
    in pFirst int unsigned,
    in pSecond int unsigned,
    in pPictureURL nvarchar(8192)
)
begin
    if exists(select Id from Relationship where Id = pId) 
    then
        update Relationship 
        set
           Since = pSince,
           Until = pUntil,
           Type = pType,
           First = pFirst,
           Second = pSecond,
           PictureURL = pPictureURL
        where
            Id = pId;

        select pId as Id;
    else
        insert into Relationship
        (
           Since,
           Until,
           Type,
           First,
           Second,
           PictureURL
        )
        values
        (
           pSince,
           pUntil,
           pType,
           pFirst,
           pSecond,
           pPictureURL
        );

        select last_insert_id() as Id;
    end if;
end //
delimiter ;

delimiter //
create or replace procedure delete_relationship (
    in pId int unsigned
)
begin
    delete Relationship
    where Id = pId;
end //
delimiter ;

知道我在做什么错吗?我已经尝试过nvarchar,但是又恢复为varchar,因为我找不到有关如何使用nvarchar的文档。

该错误消息似乎没有太大帮助,因为我试图在所示语法附近找到错误,但没有找到。

1 个答案:

答案 0 :(得分:0)

摆脱go;属于其他产品。

OR REPLACE直到10.1.3才可用;您正在运行什么版本?

Reference

相关问题