SQL SERVERÃüÁî´óÈ«£¨ÖµµÃѧϰµÄ¶«Î÷£©
ÒýÓÃ
show me µÄ SQL SERVERÃüÁî´óÈ«£¨ÖµµÃѧϰµÄ¶«Î÷£©
--Óï ¾ä ¹¦ ÄÜ
--Êý¾Ý²Ù×÷
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE --´ÓÊý¾Ý¿âÖÐɾ³ý±í
ALTER TABLE --ÐÞ¸ÄÊý¾Ý¿â±í½á¹¹
CREATE VIEW --´´½¨Ò»¸öÊÓͼ
DROP VIEW --´ÓÊý¾Ý¿âÖÐɾ³ýÊÓͼ
CREATE INDEX --ΪÊý¾Ý¿â±í´´½¨Ò»¸öË÷Òý
DROP INDEX --´ÓÊý¾Ý¿âÖÐɾ³ýË÷Òý
CREATE PROCEDURE --´´½¨Ò»¸ö´æ´¢¹ý³Ì
DROP PROCEDURE --´ÓÊý¾Ý¿âÖÐɾ³ý´æ´¢¹ý³Ì
CREATE TRIGGER --´´½¨Ò»¸ö´¥·¢Æ÷
DROP TRIGGER --´ÓÊý¾Ý¿âÖÐɾ³ý´¥·¢Æ÷
CREATE SCHEMA --ÏòÊý¾Ý¿âÌí¼ÓÒ»¸öÐÂģʽ
DROP SCHEMA --´ÓÊý¾Ý¿âÖÐɾ³ýÒ»¸öģʽ
CREATE DOMAIN --´´½¨Ò»¸öÊý¾ÝÖµÓò
ALTER DOMAIN --¸Ä±äÓò¶¨Òå
DROP DOMAIN --´ÓÊý¾Ý¿âÖÐɾ³ýÒ»¸öÓò
--Êý¾Ý¿ØÖÆ
GRANT --ÊÚÓèÓû§·ÃÎÊȨÏÞ
DENY --¾Ü¾øÓû§·ÃÎÊ
REVOKE --½â³ýÓû§·ÃÎÊȨÏÞ
--ÊÂÎñ¿ØÖÆ
COMMIT --½áÊøµ±Ç°ÊÂÎñ
ROLLBACK --ÖÐÖ¹µ±Ç°ÊÂÎñ
SET TRANSACTION --¶¨Ò嵱ǰÊÂÎñÊý¾Ý·ÃÎÊÌØÕ÷
--³ÌÐò»¯SQL
DECLARE --Ϊ²éѯÉ趨Óαê
EXPLAN --Ϊ²éѯÃèÊöÊý¾Ý·ÃÎʼƻ®
OPEN --¼ìË÷²éѯ½á¹û´ò¿ªÒ»¸öÓαê
FETCH --¼ìË÷Ò»Ðвéѯ½á¹û
CLOSE --¹Ø±ÕÓαê
PREPARE --Ϊ¶¯Ì¬Ö´ÐÐ×¼±¸SQL Óï¾ä
EXECUTE --¶¯Ì¬µØÖ´ÐÐSQL Óï¾ä
DESCRIBE --ÃèÊö×¼±¸ºÃµÄ²éѯ
---¾Ö²¿±äÁ¿
declare @id char(10)
--set @id = '10010001'
select @id = '10010001'
---È«¾Ö±äÁ¿
---±ØÐëÒÔ@@¿ªÍ·
--IF ELSE
declare @x int @y int @z int
select @x = 1 @y = 2 @z=3
if @x > @y
print 'x > y' --´òÓ¡×Ö·û´®'x > y'
else if @y > @z
print 'y > z'
else print 'z > y'
--CASE
use pangu
update employee
set e_wage =
case
when job_level = ’1’ then e_wage*1.08
when job_level = ’2’ then e_wage*1.07
when job_level = ’3’ then e_wage*1.06
else e_wage*1.05
end
--WHILE CONTINUE BREAK
declare @x int @y int @c int
select @x = 1 @y=1
while @x < 3
begin
print @x --´òÓ¡±äÁ¿x µÄÖµ
while @y < 3
begin
select @c = 100*@x + @y
print @c --´òÓ¡±äÁ¿c µÄÖµ
select @y = @y + 1
end
select @x = @x + 1
select @y =
Ïà¹ØÎĵµ£º
1¡¢×÷ÓÃ
ɾ³ýÖ¸¶¨³¤¶ÈµÄ×Ö·û£¬²¢ÔÚÖ¸¶¨µÄÆðµã´¦²åÈëÁíÒ»×é×Ö·û¡£
2¡¢Óï·¨
STUFF ( character_expression , start , length ,character_expression )
3¡¢Ê¾Àý
ÒÔÏÂʾÀýÔÚµÚÒ»¸ö×Ö·û´® abcdÖÐɾ³ý´ÓµÚ 2 ¸öλÖã¨×Ö·û b£©¿ªÊ¼µÄÈý¸ö×Ö·û£¬È ......
·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄÕûÊý¡£
Óï·¨
DATEPART ( datepart ,date )
²ÎÊý
datepart
ÊÇÖ¸¶¨Ó¦·µ»ØµÄÈÕÆÚ²¿·ÖµÄ²ÎÊý¡£Ï±íÁгöÁË Microsoft® SQL Server™ ʶ±ðµÄÈÕÆÚ²¿·ÖºÍËõд¡£
ÈÕÆÚ²¿·ÖËõд
year
yy, yyyy
quarter
qq, q
month
mm, m
dayofyear
dy, y
day
dd, d
week
wk, ww
weekda ......
×î½üÓÉÓÚϵͳµÄÐèÇó£¬ËùÒÔÒªÁ˽âÒ»ÏÂÈçºÎÓÅ»¯sql server£¬ÏÂÃæÊÇÎÒµÄһЩ×ܽᣬ²»×ãµÄµØ·½Ï£Íû´ó¼ÒÅúÆÀÖ¸Õý¡£ËµÒªÓÅ»¯´ó¼ÒÒ»¶¨»áÏëµ½Ë÷Òý£¬ÄÇÎÒÃǾʹÓË÷Òý¿ªÊ¼°É¡£ ΢ÈíµÄSQL SERVERÌṩÁËÁ½ÖÖË÷Òý£º¾Û¼¯Ë÷Òý(clustered index£¬Ò²³Æ¾ÛÀàË÷Òý¡¢´Ø¼¯Ë÷Òý)ºÍ·Ç¾Û¼¯Ë÷Òý(nonclustered index£¬Ò²³Æ·Ç¾ÛÀàË÷Òý¡¢·Ç´Ø¼¯Ë÷Òý)£¬ÏÂÃæ ......
1.×Ö·û´®º¯Êý
³¤¶ÈÓë·ÖÎöÓÃ
datalength(Char_expr) ·µ»Ø×Ö·û´®°üº¬×Ö·ûÊý,µ«²»°üº¬ºóÃæµÄ¿Õ¸ñ
substring(expression,start,length) ²»¶à˵ÁË,È¡×Ó´®
right(char_expr,int_expr) ·µ»Ø×Ö·û´®ÓÒ±ßint_expr¸ö×Ö·û
×Ö·û²Ù×÷Àà
upper(char_expr) תΪ´óд
lower(char_expr) תΪСд
space(int_expr) Éú³Éint_exp ......