当前位置: 代码迷 >> Sql Server >> 急sql脚本
  详细解决方案

急sql脚本

热度:72   发布时间:2016-04-27 14:36:34.0
急求一个sql脚本
我要修改一个已有的表结构,
table1:
 id 名字 地址 电话
现在想在“地址”前加个字段“年龄” 类型为int ,not null
请问用sql 语句怎么实现

------解决方案--------------------
语句不能控制位置

------解决方案--------------------
语句无法控制字段位置,一个替代方案,
SQL code
--转存为table2select id, 名字, 0 '年龄', 地址, 电话into table2from table1--删除table1drop table table1--重命名为table1sp_rename 'table2','table1'
------解决方案--------------------
SQL code
alter table tabel1 add [年龄] int not null
------解决方案--------------------
SQL code
 if OBJECT_ID('tb') is not null  drop table tb  go  create table tb (id int,名字 varchar(50),地址 varchar(50),电话 varchar(50))  select * from tb --现在想在“地址”前加个字段“年龄” 类型为int ,not nullalter table tb add   年龄 int NOT NULL select * from tbid          名字                                                 地址                                                 电话----------- -------------------------------------------------- -------------------------------------------------- --------------------------------------------------(0 行受影响)id          名字                                                 地址                                                 电话                                                 年龄----------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- -----------(0 行受影响
  相关解决方案