sql语句基础
--sql structured query language
--DML--Data Manipulation Language--数据操作语言
query information (SELECT),
add new rows (INSERT),
modify existing rows (UPDATE),
delete existing rows (DELETE),
perform a conditional update or insert operation (MERGE),
see an execution plan of SQL (EXPLAIN PLAN),
and lock a table to restrict access (LOCK TABLE).
--DDL--Data Definition Language--数据定义语言
create, modify,drop, or rename objects (CREATE,ALTER,DROP,RENAME),
remove all rows from a database object without dropping the structure (TRUNCATE),
manage access privileges (GRANT,REVOKE),
audit database use (AUDIT,NOAUDIT)
and add a description about an object to the dictionary (COMMENT).
--Transaction Control事务控制语句
save the changes(COMMIT)
or discard the changes (ROLLBACK) made by DML statements.
Also included in the transaction-control statements are statements to set a point or marker in the transaction for possible rollback (SAVEPOINT)
and to define the properties for the transaction (SET TRANSACTION).
Used to manage the properties of the database.
There isonly one statement in this category (ALTER SYSTEM).
--DCL--Data Control Language--与开发关系不是很密切,用于权限的分配与回收
grant,revoke,data control
--Session Control
control the session properties (ALTER SESSION)
and to enable/disable roles (SET ROLE).
--System Control
--------------------------------------------------------
select的用法
--每个员工的所有信息
select * from emp
--每个人的部门编号,姓名,薪水
select deptno,ename,sal from emp;
--每个人的年薪
select ename,sal*12 from emp;
--计算2*3的值
select 2*3 from emp;
--计算2*3的值(dual)
select 2*3 from dual;
select * from dual;
--得到当前时间
select sysdate from dual
--可以给列起别名,比如求每个人的年薪
select ename,sal*12 salperyear from emp;
--如果别名中有空格,需要用双引号
select ename,sal*12 "sal per year" from emp;
--如果没有内容,则为空
select comm from
相关文档:
ASP.NET防止SQL注入函数:
using System;
using System.Text.RegularExpressions;
using System.Web;
namespace FSqlKeyWord
......{
/**//**//**//// <summary>
/// SqlKey 的摘要说明。
/// </summary>
public class S ......
1、截断日志:
backup log 数据库 with no_log
或:
清空日志
DUMP TRANSACTION 库名 WITH NO_LOG
2、 & ......
1.bzscs(沙虫 我爱小美)用函數的好辦法:
CREATE function [dbo].[calc_date](@time smalldatetime,@now smalldatetime)
returns nvarchar(10)
as
begin
declare @year int,@month int,@day int
select @year = datediff(yy,@time,@now)
if (month(@now)=month(@time)) and (day ......
试验目的:
一、学习查询结果的排序
二、学习使用集函数的方法,完成统计
等查询。
三、学习使用分组子句
一、学习查询结果的排序
1、查询全体学生信息,结果按照年龄降
序排序
select *
from student
order by sage desc
2、查询学生选修情况,结果先按照课程
号升序排序,再按成绩降序排序
select *
from ......
--desc 表名 描述表的内容
desc emp;
--加上数学表达式和列名 ""保持格式
select ename "name space", sal*12 year_sal from emp;
select 2*3 from dual;
select sysdate from dual;
--空值的数学表达式 结果都是空值
select ename, sal*12 + comm from emp;
- ......