首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

急sql脚本

2012-03-15 
急求一个sql脚本我要修改一个已有的表结构,table1:id名字地址 电话现在想在“地址”前加个字段“年龄” 类型为

急求一个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 行受影响 

热点排行