<p>1,sql Create database语句、<br/>CREATE DATABASE MY_DB<br/><br/>2,create table语句<br/><br/>整数<br/>integer(size)<br/>int(size)<br/>smallint(size)<br/>tinyint(size)<br/><br/>容纳带小数的数字<br/>decimal(size,d)<br/>numeric(size,d)<br/><br/>varchar(size)可变长度的字符串<br/>date(yyyymmdd)容纳日期<br/><br/>Create table persons(id int,lastName varchar(255),city varchar(255)<br/><br/>sql约束<br/>Not Null,UNIque,primary key,proreign key,check,default<br/><br/>create table persions id int not null,lastName varchar(255) not Null,unique(id)<br/>撤消unique约束<br/>Alter table persons Drop Constraint UC_personid<br/><br/>primary key,check约束<br/>default<br/><br/>sql create index语句<br/>Create INDEX person index on person(lastName)<br/><br/>Create Unique INdex Index_name on table_name(column_name)<br/>Create Index personIndex on person(lastName,firstName);<br/><br/>SQL函数<br/>SELECT FUNCTION(列) form 表<br/>AVG(column)返回平均值<br/>COUNT(column)返回某列的行数,不含NULL<br/>count(*)返回被选行数<br/>first(column),last(column)最后一个纪录<br/>Max(column)返回某列的最高值<br/>Min(column)返回某列的最低值<br/>Sum(column)返回某列的总和<br/>Count(Distinct column)返回相异的结果数目<br/><br/>Scalar函数<br/>Ucase(c)大写 Lcase(c)小写<br/>Mid(c,start,end)<br/>len(c)<br/>Instr(c,char)返回指定字符数值位置<br/>Left(c,Number_of_char)<br/>Right(c,Number_of_char)<br/>Round(c,decimals)四舍五入<br/>Mod(x,y)除法取余数<br/>Now()系统当前日期<br/>Format(c,format)改变某个域的显示方式<br/>DATEDIFF(d,date1,date2)<br/><br/>应用<br/>select AVG(orderprice) as order AVege from orders<br/><br/>select customor from orders where orderprice>(select avg(orderprice) from orders)<br/><br/>select count(Distinct customer) as NumberofCustomers from orders<br/><br/>select first(orderprice) as frist order price from orders <br/>last,max,min用法同上<br/><br/>select Max(column_name) from table_name<br/>select sum(orderPrice) as orderTotay from from orders<br/><br/>select customer,sum(orderPrice) from orders group by customer<br/><br/>select customer,sum(orderprice) from orders where customer="bush" or customer='adams' group by customer Having sum(orderprice)>1500<br/><br/>select Ucase(lastName) as lastName,firstName from persons <br/>Lcase 用法同上<br/><br/>select MID(city,1,3) as Smarycity from Persons<br/>len用法<br/>select len(city) as lengthofAddress from persons<br/><br/>select productName,round(uniprice,0) as unitprice from products<br/><br/>sql format()事例<br/>select productName,Unitprice,Format(Now(),'yyyy-mm-dd') as perdate From products</p>