SQLite不支持直接修改字段类型,如需要修改字段类型,可按以下方法处理:
1、将要修改的字段名改名
2、用新的类型添加字段
3、复制原字段的内容
4、删除旧字段
procedure SQLiteAlter(TableName,ColName,NewFileType:string); var sql:string; begin sql:='ALTER TABLE '+TableName+' RENAME COLUMN '+chr(39)+ColName+chr(39)+' TO '+chr(39)+ColName+'_old'+chr(39); UniSQL1.SQL.Text:=sql; UniSQL1.Execute; sql:='ALTER TABLE '+TableName+' ADD COLUMN '+ColName+' '+ NewFileType; UniSQL1.SQL.Text:=sql; UniSQL1.Execute; sql:='UPDATE '+TableName+' SET '+ColName+' = CAST('+ColName+'_old AS '+NewFileType+')'; UniSQL1.SQL.Text:=sql; UniSQL1.Execute; sql:='ALTER TABLE '+TableName+' DROP COLUMN '+ColName+'_old'; UniSQL1.SQL.Text:=sql; UniSQL1.Execute; end; //Demo: SQLiteAlter('blog_Content','TestFieldName','nvarchar(50)');
标签:SQLite,UniSQL1,ColName,Execute,修改,chr,TableName,sql,类型 From: https://www.cnblogs.com/qiufeng2014/p/18314155