您的位置:首页 > 数据库

sql 修改表字段时会出现表字段有值 我们可以这么做

2012-08-25 11:34 267 查看
create table <new_table > as select * from <old_table>;

truncate table <old_table>;     /* 有什么约束吗?*/

alter table <old_table> modify <column> ???;
insert into  <old_table> select * from <new_table >;

1。表结构相同的表,且在同一数据库(如,table1,table2)

 Sql :insert into table1 select  *   from table2 (完全复制)

           insert into table1 select  distinct  *  from table2(不复制重复纪录)

           insert into table1 select  top 5 *  from  table2 (前五条纪录)

2。   不在同一数据库中(如,db1 table1,db2 table2)

 sql:   insert into db1..table1 select  *   from db2..table2 (完全复制)

           insert into db1..table1 select  distinct  *  from db2table2(不复制重复纪录)

           insert into tdb1..able1 select  top 5 *  from  db2table2 (前五条纪录)

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  table sql