ʹÓÃSQLÓï¾ä´´½¨Êý¾Ý¿â
ʹÓÃSQLÓï¾ä´´½¨Êý¾Ý¿â
±¾ÎÄת×Ô£ºhttp://www.cppblog.com/twzheng/archive/2008/07/07/55508.html
ÓÃCREATE DATABASE´´½¨Êý¾Ý¿âµÄÓï·¨¸ñʽ£º
CREATE DATABASE database_name /*Ö¸¶¨Êý¾Ý¿âÃû*/
[ON×Ó¾ä] /*Ö¸¶¨Êý¾Ý¿âÎļþºÍÎļþ×éÊôÐÔ*/
LOG×Ó¾ä] /*Ö¸¶¨ÈÕÖ¾ÎļþÊôÐÔ*/
Ó﷨˵Ã÷£º
a) Database_name£ºÊý¾Ý¿âÂß¼Ãû³Æ£¬×î´ó³¤¶È²»¿É³¬¹ý128¸ö×Ö·û
b)[ON×Ó¾ä]µÄÓ﷨˵Ã÷£º
ON[PRIMARY][<filespec>[,…n]][<filegroup>[,…n]]
(<filespec>[,…n]±íʾ¿É³öÏÖn¸ö<filespec>,<filegroup>[,…n]:ͬÀí)
PRIMARY£ºÖ¸¶¨Ö÷Îļþ
<filespec>Óï·¨¸ñʽ£º
<filespec>::=(NAME=’Âß¼ÎļþÃû’£¬FILE NAME=’²Ù×÷ϵͳÎļþÃû’£¬
[,SIZE=size] /*Êý¾ÝÎļþµÄ³õʼ´óС*/
[,MAXSIZE={max_size|UNLIMITED}]
/*Ö¸¶¨ÎļþµÄ×î´ó´óС*/
/* UNLIMITED£ºÎļþ´óС²»ÏÞ*/
[FILEGROWTH=growth_increament]
/* growth_increament£ºÎļþÿ´ÎµÄÔöÁ¿ )
<filegroup>Óï·¨¸ñʽ£º
<filegroup>::=FILEGROUP ’Îļþ×éÃû’ <filegroup>[,…n]
c)LOG ONÓ﷨˵Ã÷£º
Óï·¨¸ñʽ£ºLOG ON{<filespec>[,…n]} /*ÓÃÓÚÖ¸¶¨Êý¾Ý¿âÎļþµÄÊôÐÔ*/
d)ͨ¹ýSQLÃüÁî´´½¨Êý¾Ý¿âµÄ¾ßÌåʾÀý£º
CREATE DATABASE mydb ON
Ïà¹ØÎĵµ£º
×ÔÁ¬½ÓÊÇÖ¸Ò»¸ö±íÓëÆä×ÔÉí½øÐÐÁ¬½Ó¡£
¾ÙÒ»¸ö¼òµ¥µÄʵÀý£¬Ò»¸öѧÉú¿Î³Ì³É¼¨±íStudentScore£¬ÆäÖаüÀ¨Ñ§Éú±àºÅ/studentid£¬ËùÑ¡¿Î³Ì/coursename,¿Î³Ì³É¼¨/score
Ñ¡ÔñÿÃſγ̵ÄÇ°Á½ÃûѧÉú,²¢½«ËûÐÅÏ¢Êä³ö³öÀ´
´ËʱÄãµÄµÚÒ»·´Ó¦¾ÍÊÇÒª°ÑѧÉú°´ËùÑ¡¿Î³Ì½øÐзÖ×飬Ȼºó±È½Ï»ñµÃÿÃſγÌÀïÃæÇ°Á½Î»µÄѧÉú
·Ö×éµÄ·½Ê½ÓÐgroup b ......
½éÉÜGROUP BY ºÍ HAVING ×Ó¾äÇ°£¬ÎÒÃDZØÐèÏȽ²½²sqlÓïÑÔÖÐÒ»ÖÖÌØÊâµÄº¯Êý:¾ÛºÏº¯Êý£¬ÀýÈçSUM, COUNT, MAX, AVGµÈ¡£ÕâЩº¯ÊýºÍÆäËüº¯ÊýµÄ¸ù±¾Çø±ð¾ÍÊÇËüÃÇÒ»°ã×÷ÓÃÔÚ¶àÌõ¼Ç¼ÉÏ¡£
SELECT SUM(population) from bbc
ÕâÀïµÄSUM×÷ÓÃÔÚËùÓзµ»Ø¼Ç¼µÄpopulation×Ö¶ÎÉÏ£¬½á¹û¾ÍÊǸòéѯֻ·µ»ØÒ»¸ö½á¹û£¬¼´ËùÓйú¼ÒµÄ×ÜÈË¿ ......
HexString to Binary:
DECLARE @y CHAR(34)
SET @y = '0x499104dc92dd27499da9ad8f56dcb437'
DECLARE @x BINARY(16)
DECLARE @sql NVARCHAR(200)
SET @sql = 'SELECT @x = ' + @y
EXEC sp_executesql
@sql,
N'@x BINARY(16) OUTPUT',
@x OUTPUT
SELECT @x
Binary to HexString:
DECLARE @a VARBINARY(20)
SET ......
ÎÒÃÇÒª½¨Á¢¶à¼¶¹Øϵ£¬Ê×ÏÈÐèÒªÁ½¸ö±í.
µÚÒ»¸ö±í±íʾֱÊô½á¹¹£¬±ÈÈç˵ÎÒÃǹ«Ë¾ÓÐÒ»¸ö²¿ÃÅ¡£¶øÕâ¸ö²¿ÃÅÏ»¹ÓÐ3¸öС×飬ÄÇô3¸öС×éÊôÓÚÕâ¸ö²¿ÃÅ.µÚ¶þ¸ö±í±íʾ¶à²ã½á¹¹,¾ÍÏóµÚÒ»±íÀïÃæËù±íʾµÄ£¬ÕâÈý¸öС×éͬʱ»¹ÊôÓÚ¹«Ë¾.¶øÕâ¸ö¹«Ë¾Í¬Ê±ÊôÓÚÕâ3¸öС×éµÄ¸¸¼¶µÄ¸¸¼¶µÄ²¿ÃÅ¡£¼ÙÈçÎÒ ......
-- Ò»£º ´¦Àíδ²éµ½µÄ¿ÕÖµ
select
case when exists(select EndPrice from T_stock where BOMSN='0109')
then (select EndPrice from T_stock where BOMSN='0109')
else 0 end
--¶þ£º¸üÐÂ×Ö¶ÎÖµ
--strNum ÊýÁ¿
--strId ÐòºÅ
update T_buy_Pro set Co ......