2.alter table test add id int create table test (id int)
--1.如何在Sql语句中增加一列,显示所选记录的编号?从1开始按照升序排列?为:sql Server 2000数据库。alter table 你的表 add column id int identity--2.如何使用Sql语句更改Access中的以有表结构? alter table 表名 alter column 字段名 int--如何添加一个新的表? create table 表(id int,a text(20))基本的语法是一样的,很多在ACCESS中不被支持,注意字段类型
如果记录数不多,可以这样 select (select count(*) from yourtable where id<=a.id) rownum,* from yourtable a
--那你自己写代码实现标识列的功能--自已做标识列的例子:--创建得到最大id的函数 create function f_getid() returns int as begin declare @id int select @id=max(id) from tb set @id=isnull(@id,0)+1 return(@id) end go--创建表 create table tb(id int default dbo.f_getid() primary key,name varchar(10)) go--创建触发器,在删除表中的记录时,自动更新记录的id(**如果不要此功能,则删除此触发器) create trigger t_delete on tb AFTER delete as declare @id int,@mid int select @mid=min(id),@id=@mid-1 from deleted update tb set id=@id,@id=@id+1 where id>@mid go--插入记录测试 insert into tb(name) values('张三') insert into tb(name) values('张四') insert into tb(name) values('张五') insert into tb(name) values('张六') insert into tb(name) values('张七') insert into tb(name) values('张八') insert into tb(name) values('张九') insert into tb(name) values('张十')--显示插入的结果 select * from tb--删除部分记录 delete from tb where name in('张五','张七','张八','张十')--显示删除后的结果 select * from tb--删除环境 drop table tb drop function f_getid/*--测试结果 id name ----------- ---------- 1 张三 2 张四 3 张五 4 张六 5 张七 6 张八 7 张九 8 张十(所影响的行数为 8 行)id name ----------- ---------- 1 张三 2 张四 3 张六 4 张九(所影响的行数为 4 行) --*/
create table test (id int)
alter table 表名 alter column 字段名 int--如何添加一个新的表?
create table 表(id int,a text(20))基本的语法是一样的,很多在ACCESS中不被支持,注意字段类型
我不想使用临时表,这个比较麻烦,其它的就没有方法了吗?TO:回复人: LoveSQL(努力奋斗ing)
这些语法在sql Server中应该是可以的,但在Access中好像不好用。
select (select count(*) from yourtable where id<=a.id) rownum,* from yourtable a
create function f_getid()
returns int
as
begin
declare @id int
select @id=max(id) from tb
set @id=isnull(@id,0)+1
return(@id)
end
go--创建表
create table tb(id int default dbo.f_getid() primary key,name varchar(10))
go--创建触发器,在删除表中的记录时,自动更新记录的id(**如果不要此功能,则删除此触发器)
create trigger t_delete on tb
AFTER delete
as
declare @id int,@mid int
select @mid=min(id),@id=@mid-1 from deleted
update tb set id=@id,@id=@id+1 where id>@mid
go--插入记录测试
insert into tb(name) values('张三')
insert into tb(name) values('张四')
insert into tb(name) values('张五')
insert into tb(name) values('张六')
insert into tb(name) values('张七')
insert into tb(name) values('张八')
insert into tb(name) values('张九')
insert into tb(name) values('张十')--显示插入的结果
select * from tb--删除部分记录
delete from tb where name in('张五','张七','张八','张十')--显示删除后的结果
select * from tb--删除环境
drop table tb
drop function f_getid/*--测试结果
id name
----------- ----------
1 张三
2 张四
3 张五
4 张六
5 张七
6 张八
7 张九
8 张十(所影响的行数为 8 行)id name
----------- ----------
1 张三
2 张四
3 张六
4 张九(所影响的行数为 4 行)
--*/
下班前结贴.