存储过程判断该列是否存在,有则删除在添加

28 篇文章 1 订阅

drop procedure if exists schema_change;  

delimiter ';;';  

create procedure schema_change() begin  

if exists (select * from information_schema.columns where table_name = 'sales_order' and column_name = 'has_sent') then  

        alter table sales_order drop column has_sent;  

end if;  

alter table sales_order add column has_sent boolean;  

end;;  

delimiter ';';  

call schema_change();  

drop procedure if exists schema_change; 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我可以帮你解答这个问题。以下是一个简单的课程管理系统的C语言实现,包含添加课程、删除课程和输出所有课程的功能。注释详细解释了每个步骤的作用。 ```c #include <stdio.h> #include <string.h> // 定义一个二维字符数组,用于存储课程信息 char courses[100][50]; // 记录当前已经添加了多少门课程 int courseCount = 0; // 添加课程函数 void addCourse() { char name[50]; // 获取要添加的课程名 printf("请输入要添加的课程名:"); scanf("%s", name); // 判断该课程是否已存在 for (int i = 0; i < courseCount; i++) { if (strcmp(courses[i], name) == 0) { printf("该课程已存在!\n"); return; } } // 课程不存在,则添加课程 strcpy(courses[courseCount], name); courseCount++; printf("添加课程成功!\n"); } // 删除课程函数 void removeCourse() { char name[50]; // 获取要删除的课程名 printf("请输入要删除的课程名:"); scanf("%s", name); // 判断该课程是否存在 for (int i = 0; i < courseCount; i++) { if (strcmp(courses[i], name) == 0) { // 课程存在,则删除课程 for (int j = i; j < courseCount - 1; j++) { strcpy(courses[j], courses[j+1]); } courseCount--; printf("删除课程成功!\n"); return; } } // 课程不存在,则删除失败 printf("该课程不存在!\n"); } // 输出所有课程函数 void printCourses() { if (courseCount == 0) { printf("还没有课程!\n"); return; } printf("所有课程:\n"); for (int i = 0; i < courseCount; i++) { printf("%s\n", courses[i]); } } int main() { int choice; do { printf("请选择功能:\n"); printf("1. 添加课程\n"); printf("2. 删除课程\n"); printf("3. 输出所有课程\n"); printf("4. 退出\n"); scanf("%d", &choice); switch (choice) { case 1: addCourse(); break; case 2: removeCourse(); break; case 3: printCourses(); break; case 4: printf("再见!\n"); break; default: printf("输入有误,请重新输入!\n"); break; } } while (choice != 4); return 0; } ``` 希望这个例子可以帮到你,如果还有其他问题,请随时问我!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值