数据库更新迭代

数据库更新迭代方法一:

http://blog.csdn.net/shan1991fei/article/details/50894436

这是一种原始的写法。

数据库更新迭代方法一:

pod 'FMDB', '~> 2.6.2'
pod 'FMDBMigrationManager', '~>1.4.1'

#pragma mark - 迁移
-(void)migrations
{
    //删除列:@"alter table record drop column name"
    dispatch_sync([QueueFetcher getInstance].dbQueue, ^{
        //数据库版本升级//DBPath是要升级的数据库的地址
        NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
        NSString *dpPath = [docsPath stringByAppendingPathComponent:_NAME_DATABASE];
        NSLog(@"这是迁移数据库地址:==%@",dpPath);
        // [NSBundle mainBundle]是保存数据库升级文件的位置 根据自己放文件的位置定 升级文件是什么下面会说
        FMDBMigrationManager *manger = [FMDBMigrationManager managerWithDatabaseAtPath:dpPath migrationsBundle:[NSBundle mainBundle]];
        NSString *strDBM1_1 = [NSString stringWithFormat:@"alter table %@ add %@ text",TABLE_NAME,EMAIL];
        MigrationZ *migraA_1 = [[MigrationZ alloc]initWithName:@"添加邮箱email字段" andVersion:_DB_V_2 andExecuteUpdateArray:@[strDBM1_1]];
        [manger addMigration:migraA_1];
        
        NSError * error;
        BOOL result =NO;
        if (!manger.hasMigrationsTable) {
            result=[manger createMigrationsTable:&error];
        }
        
        result=[manger migrateDatabaseToVersion:UINT64_MAX progress:nil error:&error];
        if(result)
        {
            NSLog(@"迁移表成功 %@",TABLE_NAME);
        }
        else
        {
            NSLog(@"迁移表失败 %@",TABLE_NAME);
        }
        /**
         //第二种方式:
         MigrationZ * migration_1=[[MigrationZ alloc]initWithName:@"新增USer表" andVersion:1 andExecuteUpdateArray:@[@"create table User(name text,age integer)",@"create table Zhuzhu(name text,age integer)",@"create table Dong(name text,age integer)"]];
         
         MigrationZ * migration_2=[[MigrationZ alloc]initWithName:@"USer表新增字段email,Zhuzhu表新增字段email" andVersion:2 andExecuteUpdateArray:@[@"alter table User add email text",@"alter table Zhuzhu add email text"]];
         
         MigrationZ * migration_3=[[MigrationZ alloc]initWithName:@"USer表新增字段adrive" andVersion:3 andExecuteUpdateArray:@[@"alter table User add adrive text",@"alter table Dong add adrive text"]];
         
         [manager addMigration:migration_1];
         [manager addMigration:migration_2];
         [manager addMigration:migration_3];*/
        
    });
}


使用第三方:经测试使用稳定。有一个小技巧:只要有表发生改变时

“andVersion:_DB_V_2“就增加。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据库迭代查询作业 emp(eno, ename, salary, mgr),其中mgr是员工领导,设计约束:要求领导的工资不能低于他的下属平均工资。(注意,这是一个递归查询) 下面是一些样例数据 CREATE TABLE dbo.Employees ( empid INT NOT NULL PRIMARY KEY, mgrid INT NULL REFERENCES dbo.Employees, empname VARCHAR(25) NOT NULL, salary MONEY NOT NULL, CHECK (empid mgrid) ); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(1, NULL, 'David', $10000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(2, 1, 'Eitan', $7000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(3, 1, 'Ina', $7500.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(4, 2, 'Seraph', $5000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(5, 2, 'Jiru', $5500.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(6, 2, 'Steve', $4500.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(7, 3, 'Aaron', $5000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(8, 5, 'Lilach', $3500.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(9, 7, 'Rita', $3000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(10, 5, 'Sean', $3000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(11, 7, 'Gabriel', $3000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(12, 9, 'Emilia' , $2000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(13, 9, 'Michael', $2000.00); INSERT INTO dbo.Employees(empid, mgrid, empname, salary) VALUES(14, 9, 'Didi', $1500.00);

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值