DROP PROCEDURE proc_morefight; DELIMITER $$ CREATE PROCEDURE proc_morefight() BEGIN select * FROM table_fight; END $$ DELIMITER ; CALL proc_morefight(); 改成sql server语言
时间: 2024-01-31 14:02:00 浏览: 79
在 SQL Server 中,需要使用 `GO` 语句分隔不同的批处理命令。下面是将这段代码转换成 SQL Server 语言的示例:
```
IF OBJECT_ID('proc_morefight', 'P') IS NOT NULL
DROP PROCEDURE proc_morefight;
GO
CREATE PROCEDURE proc_morefight
AS
BEGIN
SELECT * FROM table_fight;
END;
GO
EXEC proc_morefight;
```
这里的 `IF OBJECT_ID` 语句用于检查存储过程是否存在,如果存在则先删除。然后使用 `CREATE PROCEDURE` 语句创建存储过程。在存储过程的主体中,使用 `SELECT` 语句查询 `table_fight` 表的所有数据。最后,使用 `EXEC` 语句调用存储过程。注意,在 SQL Server 中不需要 `DELIMITER` 语句。
相关问题
CREATE PROCEDURE proc_fight() BEGIN select * FROM view_fight; END $$ DELIMITER ; CALL proc_fight();改为sql server语言
在 SQL Server 中,不需要使用 `DELIMITER` 语句来指定语句的结束符。下面是将这段代码转换成 SQL Server 语言的示例:
```
CREATE PROCEDURE proc_fight
AS
BEGIN
SELECT * FROM view_fight;
END;
EXEC proc_fight;
```
这里的 `CREATE PROCEDURE` 语句用于创建存储过程 `proc_fight`,其中 `AS` 之后的语句是存储过程的主体。在主体中,使用 `SELECT` 语句查询 `view_fight` 视图的所有数据。最后,使用 `EXEC` 语句调用存储过程。
DELIMITER $$ CREATE PROCEDURE proc_reserve_nanhang() BEGIN select (select count(table_ticket.fight_no ) from table_ticket WHERE fight_no LIKE "南航CZ3172")as num1, (select table_air.air_setting from table_air INNER JOIN table_fight ON table_fight.air_model=table_air.air_model WHERE fight_no LIKE "南航CZ3172" )as num2, case when (select count(table_ticket.fight_no) from table_ticket WHERE fight_no LIKE "南航CZ3172") =(select table_air.air_setting from table_air INNER JOIN table_fight ON table_fight.air_model=table_air.air_model WHERE fight_no LIKE "南航CZ3172" ) then '未售空' when (select count(table_ticket.fight_no ) from table_ticket WHERE fight_no LIKE "南航CZ3172") >(select table_air.air_setting from table_air INNER JOIN table_fight ON table_fight.air_model=table_air.air_model WHERE fight_no LIKE "南航CZ3172" ) then '已售空' else '未售空' end as '南航CZ3172机票状态'; END $$ DELIMITER ; CALL proc_reserve_nanhang(); 改写为sql server语言
以下是将MySQL存储过程改写为SQL Server存储过程的代码:
```
CREATE PROCEDURE proc_reserve_nanhang
AS
BEGIN
SELECT
(SELECT COUNT(fight_no) FROM table_ticket WHERE fight_no LIKE '南航CZ3172') AS num1,
(SELECT air_setting FROM table_air INNER JOIN table_fight ON table_fight.air_model = table_air.air_model WHERE fight_no LIKE '南航CZ3172') AS num2,
CASE
WHEN (SELECT COUNT(fight_no) FROM table_ticket WHERE fight_no LIKE '南航CZ3172') = (SELECT air_setting FROM table_air INNER JOIN table_fight ON table_fight.air_model = table_air.air_model WHERE fight_no LIKE '南航CZ3172')
THEN '未售空'
WHEN (SELECT COUNT(fight_no) FROM table_ticket WHERE fight_no LIKE '南航CZ3172') > (SELECT air_setting FROM table_air INNER JOIN table_fight ON table_fight.air_model = table_air.air_model WHERE fight_no LIKE '南航CZ3172')
THEN '已售空'
ELSE '未售空'
END AS '南航CZ3172机票状态';
END
```
需要注意的是,在 SQL Server 中不需要使用 `DELIMITER` 命令来指定语句分隔符,因此在这个存储过程中将其删除了。此外,SQL Server 中不支持在 `SELECT` 语句中使用 `AS` 关键字来为列设置别名,因此需要将别名移动到 `END AS` 子句中。
阅读全文