在一个字段的左边和右边添加东西:
update 表 set 字段A=left(字段A,左边几位) +‘要加什么’+right(字段A,右边几位) where len(字段A)=2
把查询到的东西生成一个新表abc:
select 表1.字段1,表1.字段2,表2.字段3,表2.字段4 from 表1 left join 表2 on 表1.字段1=表2.字段1
update 表 set 字段A=left(字段A,左边几位) +‘要加什么’+right(字段A,右边几位) where len(字段A)=2
把查询到的东西生成一个新表abc:
select 字段1,字段2,字段3 into abc from 表1
连接查询:
select 表1.字段1,表1.字段2,表2.字段3,表2.字段4 from 表1 left join 表2 on 表1.字段1=表2.字段1
union 用于连接两个查询
--查询表中一共有多少列
select count(*) from syscolumns s where s.id = object_id('表')
--查询表中一共有多少行
select count(*) from 表
--查询表中的字段类型字段长度.
--查询表中的字段类型字段长度.
select a.name 表名,b.name 字段名,c.name 字段类型,c.length 字段长度 from sysobjects a,syscolumns b,systypes c wherea.id=b.id
and a.name='表' and a.xtype='U'
and b.xtype=c.xtype and b.name='字段'
--在表中增加一列. char字段查询都是8000,不能查询出来。
alter table 表 add 字段 char(1)
--在把表1中的字段增加一列自增数插入表中。
select IDENTITY(int,1,1) as id,* into 表 from 表1
select * from 表
--在把表1中的字段增加一列自增数插入表中。
select IDENTITY(int,1,1) as id,* into 表 from 表1
select * from 表
IDENTITY(a,b),ab均为正整数,a表示开始数,b表示增幅
转载请注明:不可不知 » 软件方案 » 几个常用的SQL语句
发表评论