初学者的小手册:Transact_SQL
2007-11-11 04:18:53 来源:WEB开发网核心提示: ·如何使用sql server(WINDOWS平台上强大的数据库平台)客户端配置工具·SQL2000无法安装的解决办法·sql server(WINDOWS平台上强大的数据库平台)2000 索引结构及其使用·全面接触SQL语法·SQL语法参考手册(
- ·如何使用sql server(WINDOWS平台上强大的数据库平台)客户端配置工具
·SQL2000无法安装的解决办法
·sql server(WINDOWS平台上强大的数据库平台)2000 索引结构及其使用
·全面接触SQL语法
·SQL语法参考手册(SQL)
·ms sql删除重复的记录
·PL/SQL开发中动态SQL的使用方法
·很久以前的一个sql面试题及答案.
·Transact SQL 常用语句以及函数
·sql server(WINDOWS平台上强大的数据库平台)连接失败错误分析与排除
select *(列名) from table_name(表名) where column_name operator value ex:(宿主)
select * from stock_information where stockid = str(nid)
stockname = 'str_name'
stockname like '% find this %'
stockname like '[a-zA-Z]%' --------- ([]指定值的范围)
stockname like '[^F-M]%' --------- (^排除指定范围)
--------- 只能在使用like关键字的where子句中使用通配符)
or stockpath = 'stock_path'
or stocknumber < 1000
and stockindex = 24
not stocksex = 'man'
stocknumber between 20 and 100
stocknumber in(10,20,30)
order by stockid desc(asc) --------- 排序,desc-降序,asc-升序
order by 1,2 --------- by列号
stockname = (select stockname from stock_information where stockid = 4)
--------- 子查询
--------- 除非能确保内层select只返回一个行的值
--------- 否则应在外层where子句中用一个in限定符
select distinct column_name form table_name
--------- distinct指定检索独有的列值,不重复
select stocknumber ,"stocknumber + 10" = stocknumber + 10 from table_name
select stockname , "stocknumber" = count(*) from table_name group by stockname
--------- group by 将表按行分组,指定列中有相同的值
having count(*) = 2 --------- having选定指定的组
select *
from table1, table2
where table1.id *= table2.id -------- 左外部连接,table1中有的而table2中没有得以null表示
table1.id =* table2.id -------- 右外部连接
select stockname from table1
union [all] -------- union合并查询结果集,all-保留重复行
select stockname from table2
insert
insert into table_name (Stock_name,Stock_number) value ("xxx","xxxx")
value (select Stockname , Stocknumber from Stock_table2)
-------value为select语句
update
update table_name set Stockname = "xxx" [where Stockid = 3]
Stockname = default
Stockname = null
Stocknumber = Stockname + 4
delete
delete from table_name where Stockid = 3
truncate table_name --------- 删除表中所有行,仍保持表的完整性
drop table table_name --------- 完全删除表
alter table -------- 修改数据库表结构
alter table database.owner.table_name add column_name char(2) null .....
sp_help table_name -------- 显示表已有特征
create table table_name (name char(20), age smallint, lname varchar(30))
insert into table_name select .........-------- 实现删除列的方法(创建新表)
alter table table_name drop constraint Stockname_default
--------- 删除Stockname的default约束
更多精彩
赞助商链接