常用sql相关
1修改基本表
添加列 alter table tableName add<新列名><数据类型>[完整性约束]
删除列 alter table tableName drop<新列名><数据类型>[完整性约束]
2创建
建表create table tableName(
id primary key AUTO_INCREMENT(mysql);
id primary key identity(1,1)(sql server)
)
建立索引
create index OID_IDX on 表名(number);
create unique index oin_idx on 表名(number);创建唯一索引
3 删除
删除索引 drop index <索引名>
删除表 drop table <表名>
4 sql功能
数据查询 select
数据定义 create drop alter
数据操控 insert update delete
数据控制 grant(授权) revoke(收回权限)
(1) 数据查询
select * from tableName where <条件表达式> group by<列名>[having<条件>] order by<列名>[ASC DESC]
select distinct Sno from sc 查询数据去掉重复行
常见的查询条件
比较 = ,>,<,<=,<=,!=,<>,!<,!>,
确定范围 between and |not between and
确定集合 in ,not in
字符匹配 like ,not like like '<匹配符>' 匹配符可以包含通配符%和_
空值 is null ,is not null
多重条件(逻辑运算) and,or,not
select a.name,a.mialbox from a where EXISTS(select b.name from b where a.name=b.name)
联接查询join
select a.number,a,name,b.age,b.sort from a join b on a.number=b.number
inner join 内联接 用于返回两个表中要查询的列数据 left join right join
常见运算以及聚集函数
ABS(x)返回绝对值
&
相关文档:
例子: int id = Convert.ToInt32(replace((Request.QueryString["id"]), ""));
public static string replace(string str, string str2)
{
str = str.Replace(";", str2);
str = ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
......
--查询现在日期,只要年月日
select convert(varchar(10),getDate(),120)
--查询现在日期,只要时分秒
select convert(varchar(8),getDate(),8)
Convert函数的一些说明,以下资料来源于网络
不带世纪数位 (yy)
带世纪数位 (yyyy)
标准
输入 ......
几道经典的SQL笔试题目(有答案)
(1)表名:购物信息
购物人 商品名称 数量
A 甲 2
B 乙 &n ......
转载:http://blog.csdn.net/cnming/archive/2009/03/11/3979290.aspx
在查询分析器中顺序执行以下三步,其中 databasename 为你的数据库文件名
1.清空日志:DUMP TRANSACTION databasename WITH NO_LOG
2.截断事务日志:BACKUP ......