如何在多个 DataGrip 查询中使用一个变量?
How to use a variable in multiple DataGrip queries?
鉴于我有一堆疑问
例如
delete from permissions where user_id = 9845 and project_id =2;
delete from users_projects where user_id = 9845 and project_id =2;
delete from users where id = 9845 and project_id =2;
如何避免每次 运行 这些时都必须在每个查询中更新 user_id?
理想情况下,像
var userId = 9845
delete from permissions where user_id = userId and project_id =2;
delete from users_projects where user_id = userId and project_id =2;
delete from users where id = userId and project_id =2;
我尝试使用 ?
和 :userId
例如
delete from permissions where user_id = :userId and project_id =2;
delete from users_projects where user_id = :userId and project_id =2;
delete from users where id = :userId and project_id =2;
这会提示我通过对话框输入用户 ID,这很好,但我必须为每一行输入 ir。
我希望能够更新一个地方/输入一次值。
DataGrip 可以吗?
您可以使用 ${variable_name}
语法为查询输入一次值:
delete from permissions where user_id = ${userId} and project_id =2;
delete from users_projects where user_id = ${userId} and project_id =2;
delete from users where id = ${userId} and project_id =2;
鉴于我有一堆疑问 例如
delete from permissions where user_id = 9845 and project_id =2;
delete from users_projects where user_id = 9845 and project_id =2;
delete from users where id = 9845 and project_id =2;
如何避免每次 运行 这些时都必须在每个查询中更新 user_id?
理想情况下,像
var userId = 9845
delete from permissions where user_id = userId and project_id =2;
delete from users_projects where user_id = userId and project_id =2;
delete from users where id = userId and project_id =2;
我尝试使用 ?
和 :userId
例如
delete from permissions where user_id = :userId and project_id =2;
delete from users_projects where user_id = :userId and project_id =2;
delete from users where id = :userId and project_id =2;
这会提示我通过对话框输入用户 ID,这很好,但我必须为每一行输入 ir。
我希望能够更新一个地方/输入一次值。
DataGrip 可以吗?
您可以使用 ${variable_name}
语法为查询输入一次值:
delete from permissions where user_id = ${userId} and project_id =2;
delete from users_projects where user_id = ${userId} and project_id =2;
delete from users where id = ${userId} and project_id =2;