Question: Just for learning purposes, I'm trying to create a function using PLPGSQL and make an SQL injection on it. I recently learned about `format`, `USING` and `quote_literal` and `quote_indent`, so I'm good about avoiding an SQL injection. What I'm trying to do is create a function that allows an SQL injection (i.e. a `drop table`).

So I wrote this:

```
create or replace function badfunc(tablename text, identifier int4)
returns setof character varying as $$
declare
    query text;
begin
    query := 'select full_name from ' || $1 || ' where re = ' || $2 ||'';
    raise notice 'query: %', query;
    return query execute query;
end;
$$ language 'plpgsql';

```

But when I execute this function with `select badfunc('; drop table tb_students;', 1001);` I get this error:

```
[42601] ERROR: syntax error at or near ";" where: function PL/pgSQL badfunc(text,integer) linha 7 in RETURN QUERY

```

So I think that's not how it is done. How can I achieve this SQL injection?

Answer: 
Use T-SQL directly instead of the GUI to do the restore. You can script the RESTORE command from the GUI. If you add that RESTORE command to your post, we have something to go on.

Anyhow, the error message suggests that the database name you try to restore into already exists, and a type of safety check by MSSQL steps in so you don't overwrite something by mistake.

If this is the case (which, again, the error message is saying), then your options are:

1. Delete the existing database named "From\_Backup\_Customer" befor the restore, so it doesn't exist.
2. Use the REPLACE option to the RESTORE command. This is available as a checkbox in the RESTORE GUI.
A colleague has provided me with a solution: simply create another SQL-server server. I don't know the exact tool he used for doing that, but the result in the Microsoft SQL-server Management Studio looks as follows:

[![enter image description here](https://i.stack.imgur.com/2dDG6.png)](https://i.stack.imgur.com/2dDG6.png)