³£ÓÃ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 = ......
ÔÚsqlÖд´½¨Óû§×Ô¶¨Ò寴Òôº¯Êý£º
create function f_GetPy(@Str nvarchar(400))
returns nvarchar(4000)
as
begin
declare @strlen int,@re nvarchar(4000)
declare @t table(chr nchar(1) collate Chinese_PRC_CI_AS,letter nchar(1))
insert @t select 'ß¹','A' union all select '°Ë','B'
union all select 'àê ......
--²éѯÏÖÔÚÈÕÆÚ£¬Ö»ÒªÄêÔÂÈÕ
select convert(varchar(10),getDate(),120)
--²éѯÏÖÔÚÈÕÆÚ£¬Ö»ÒªÊ±·ÖÃë
select convert(varchar(8),getDate(),8)
Convertº¯ÊýµÄһЩ˵Ã÷£¬ÒÔÏÂ×ÊÁÏÀ´Ô´ÓÚÍøÂç
²»´øÊÀ¼ÍÊýλ (yy)
´øÊÀ¼ÍÊýλ (yyyy)
±ê×¼
ÊäÈë ......
¼¸µÀ¾µäµÄSQL±ÊÊÔÌâÄ¿£¨Óд𰸣©
£¨1£©±íÃû£º¹ºÎïÐÅÏ¢
¹ºÎïÈË ÉÌÆ·Ãû³Æ ÊýÁ¿
A ¼× 2
B ÒÒ &n ......
1¡¢²éÕÒÔ±¹¤µÄ±àºÅ¡¢ÐÕÃû¡¢²¿ÃźͳöÉúÈÕÆÚ£¬Èç¹û³öÉúÈÕÆÚΪ¿ÕÖµ£¬ÏÔʾÈÕÆÚ²»Ïê,²¢°´²¿ÃÅÅÅÐòÊä³ö,ÈÕÆÚ¸ñʽΪyyyy-mm-dd¡£
select
emp_no,emp_name,dept,isnull(convert(char(10),birthday,120),'ÈÕÆÚ²»Ïê') birthday
from employee
order by dept
¡¡¡¡
2¡¢²éÕÒÓëÓ÷×ÔÇ¿ÔÚͬһ¸öµ¥Î»µÄÔ±¹¤ÐÕÃû¡¢ÐÔ±ð¡ ......