在这两天的招聘 笔试 面试中 发现了许多不足 特别是对sql server 的一些知识的匮乏 分享一些给大家
1.选择最有效率的表名顺序 FROM子句按照从右到左的顺序处理,记录条数最少的,交叉表,放右 WHERE子句采用自下而上的顺序解析,可以过滤掉最大数量记录的条件必须写在WHERE子句的末尾.
2.删除表字段
ALTER TABLE t_table DROP COLUMN name;
3.在多个分支中,不能同时向一个临时表用select...into...from,比较笨的一种解决办法就是同时使用select...into...from 和insert into... select from ...。用select...into...from的时候创建临时表,而用insert into...select from...不会创建表,只会向已有的表中添加数据。
4.条件中对于索引字段尽量不要使用函数。因为这样不会使用到索引。
5.不要过多的表联合查询,最好不要超过三个。越少越好,可以适当使用临时表。尽可能用唯一条件进行关联。
6.对于使用比较频繁或估计以后会处理较多数据的地方,应构造尽可能多的数据进行 测试,以便发现效率问题。
7.sql预处理语句 设置stmt1预处理: prepare stmt1 from 'select * from t where id>?' 设置一个变量: set @i = 1; 执行stmt1预处理:execute stmt1 using @i set @i=5 execute stmt1 using @i 删除预处理:drop prepare stmt1
8.数据库加密:
select encrypt('原始密码')
select pwdencrypt('原始密码')
select pwdcompare('原始密码','加密后密码') = 1--相同;否则不相同 encrypt('原始密码')
select pwdencrypt('原始密码')
select pwdcompare('原始密码','加密后密码') = 1--相同;否则不相同
9.将现有表数据添加到一个已有表insert into <已有的新表> (列名) select <原表列名> from <原表名>
删除整个表truncate table <表名> truncate table tongxunlu
改 update <表名> set <列名=更新值> [where <更新条件>]
精确(条件)查询select <列名> from <表名> [where <查询条件表达试>] [order by <排序的列名>[asc或desc]]
查询所有数据行和列select * from a
查询部分行列--条件查询select i,j,k from a where f=5
在查询中使用常量select name, '山东' as 地址 from Student
查询排序(关键字:order by , asc , desc)select name from a where chengji>=60 order by desc
在where子句中指定联接条件 select a.name,b.chengji from a,b where a.name=b.name