sql µÄËæ»úº¯ÊýnewID()ºÍRAND()
sql serverµÄËæ»úº¯ÊýnewID()ºÍRAND()¡¡¡¡
¡¡¡¡SELECT * from Northwind..Orders ORDER BY NEWID()
¡¡¡¡--Ëæ»úÅÅÐò
¡¡¡¡SELECT TOP 10 * from Northwind..Orders ORDER BY NEWID()
¡¡¡¡--´ÓOrders±íÖÐËæ»úÈ¡³ö10Ìõ¼Ç¼¡¡¡¡
¡¡¡¡Ê¾Àý¡¡¡¡
¡¡¡¡A.¶Ô±äÁ¿Ê¹Óà NEWID º¯Êý
¡¡¡¡ÒÔÏÂʾÀýʹÓà NEWID() ¶ÔÉùÃ÷Ϊ uniqueidentifier Êý¾ÝÀàÐ͵ıäÁ¿¸³Öµ¡£ÔÚ²âÊÔ uniqueidentifier Êý¾ÝÀàÐͱäÁ¿µÄֵ֮ǰ£¬ÏÈÊä³ö¸ÃÖµ¡£
¡¡¡¡-- Creating a local variable with DECLARESET syntax.
¡¡¡¡DECLARE @myid uniqueidentifier
¡¡¡¡SET @myid = NEWID()
¡¡¡¡PRINT 'Value of @myid is '+ CONVERT(varchar(255), @myid)
¡¡¡¡ÏÂÃæÊǽá¹û¼¯£º
¡¡¡¡Value of @myid is 6F9619FF-8B86-D011-B42D-00C04FC964FF
¡¡¡¡×¢Ò⣺
¡¡¡¡NEWID ¶Ôÿ̨¼ÆËã»ú·µ»ØµÄÖµ¸÷²»Ïàͬ¡£ËùÏÔʾµÄÊý×Ö½öÆð½âÊÍ˵Ã÷µÄ×÷Óᣡ¡¡¡
¡¡¡¡Ëæ»úº¯Êý£ºrand()
¡¡¡¡ÔÚ²éѯ·ÖÎöÆ÷ÖÐÖ´ÐУºselect rand()£¬¿ÉÒÔ¿´µ½½á¹û»áÊÇÀàËÆÓÚÕâÑùµÄËæ»úСÊý£º0.36361513486289558£¬ÏñÕâÑùµÄСÊýÔÚʵ¼ÊÓ¦ÓÃÖÐÓõò»¶à£¬Ò»°ãҪȡËæ»úÊý¶¼»áÈ¡Ëæ»úÕûÊý¡£ÄǾͿ´ÏÂÃæµÄÁ½ÖÖËæ»úÈ¡ÕûÊýµÄ·½·¨£º ¡¡¡¡
¡¡¡¡1¡¢
¡¡¡¡A£ºselect floor(rand()*N) ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12.0
¡¡¡¡B£ºselect cast( floor(rand()*N) as int) ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12 ¡¡¡¡
¡¡¡¡2¡¢
¡¡¡¡A£ºselect ceiling(rand() * N) ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12.0
¡¡¡¡B£ºselect cast(ceiling(rand() * N) as int) ---Éú³ÉµÄÊýÊÇÕâÑùµÄ£º12 ¡¡¡¡
¡¡¡¡ÆäÖÐÀïÃæµÄNÊÇÒ»¸öÄãÖ¸¶¨µÄÕûÊý£¬Èç100£¬¿ÉÒÔ¿´³ö£¬Á½ÖÖ·½·¨µÄA·½·¨ÊÇ´øÓÐ.0Õâ¸öµÄСÊýµÄ£¬¶øB·½·¨¾ÍÊÇÕæÕýµÄÕûÊýÁË¡£
´óÖÂÒ»¿´£¬ÕâÁ½ÖÖ·½·¨Ã»Ê²Ã´Çø±ð£¬ÕæµÄûÇø±ð£¿ÆäʵÊÇÓÐÒ»µãµÄ£¬ÄǾÍÊÇËûÃǵÄÉú³ÉËæ»úÊýµÄ·¶Î§£º
¡¡¡¡·½·¨1µÄÊý×Ö·¶Î§£º0ÖÁN-1Ö®¼ä£¬Èçcast( floor(rand()*100) as int)¾Í»áÉú³É0ÖÁ99Ö®¼äÈÎÒ»ÕûÊý
¡¡¡¡·½·¨2µÄÊý×Ö·¶Î§£º1ÖÁNÖ®¼ä£¬Èçcast(ceiling(rand() * 100) as int)¾Í»áÉú³É1ÖÁ100Ö®¼äÈÎÒ»ÕûÊý
¡¡¡¡¶ÔÓÚÕâ¸öÇø±ð£¬¿´SQLµÄÁª»ú°ïÖú¾ÍÖªÁË£º¡¡¡¡
¡¡¡¡±È½Ï CEILING ºÍ FLOOR
¡¡¡¡CEILING º¯Êý·µ»Ø´óÓÚ»òµÈÓÚËù¸øÊý×Ö±í´ïʽµÄ×îСÕûÊý¡£FLOOR º¯Êý·µ»ØСÓÚ»òµÈÓÚËù¸øÊý×Ö±í´ïʽµÄ×î´óÕûÊý¡£ÀýÈ磬¶ÔÓÚÊý×Ö±í´ïʽ 12.9273£¬CEILING ½«·µ»Ø 13£¬FLOOR ½«·µ»Ø 12¡£FLOOR ºÍ CEILING ·µ»ØÖµµÄÊý¾ÝÀàÐͶ¼ÓëÊäÈëµÄÊý×Ö±í´ïʽµÄÊý¾ÝÀàÐÍÏàͬ¡£
¡¡¡¡ÏÖÔ
Ïà¹ØÎĵµ£º
£¬SQLÓиö³¬¼¶Óû§sa£¬´ËÓû§Ä¬ÈÏÇé¿öÏ£¬ËüÖ¸Åɸø¹Ì¶¨·þÎñÆ÷½ÇÉ« sysadmin£¬²¢²»ÄܽøÐиü¸Ä¡£Ò»°ã¶®µã°²È«ÎÊÌâµÄ¼¼ÊõÈËÔ±¶¼»á°ÑÕâ¸öÃÜÂëÐ޸ĵô£¬µ«ÐÞ¸ÄÔÙ¸´ÔÓµÄÃÜÂ붼²»ÊǾø¶Ô°²È«µÄ£¬Ò»Ð©±©Á¦ÆƽâÈí¼þ£¬²ËÄñ¶¼»áÓá£
ÄÇÔõô°ìÄØ£¬×îºÃµÄ°ì·¨¾ÍÊÇɾ³ý»ò¸ÄÃû£¬ÏÂÃæÌṩ·½·¨.
ÐÞ¸ÄSAÓû§Ãû£º
Ò»£ºÔÚÆóÒµ¹ÜÀíÆ÷ÖÐÓÒ»÷£º(lo ......
ÓÃSQL²éѯ·ÖÎöÆ÷²Ù×ÝExcel¼°µ¼Èëµ¼³öÊý¾Ý
http://www.delphibbs.com/keylife/iblog_show.asp?xid=32983
SQL SERVER ºÍEXCELµÄÊý¾Ýµ¼Èëµ¼³ö
ͨ³£µÄ·½·¨ÊÇʹÓÃͼÐνçÃæµÄdts¹¤¾ß£¬µ«·¢¾õÓÐЩʹÓÃÃüÁîÐнçÃæµÄ·½Ê½¸ü¼òµ¥
1¡¢ÔÚSQL SERVERÀï²éѯExcelÊý¾Ý:
-- ======================================================
SE ......
ÓÃSQL²éѯ·ÖÎöÆ÷²Ù×÷Excel
http://hi.baidu.com/bilbit/blog/item/adf7a33427af52bed0a2d38e.html
SQL SERVER ºÍEXCELµÄÊý¾Ýµ¼Èëµ¼³ö
1¡¢ÔÚSQL SERVERÀï²éѯExcelÊý¾Ý:
-- ======================================================
SELECT *
from OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\boo ......
SQLÓÃselectÓï¾ä²éѯÖظ´¼Ç¼
http://hi.baidu.com/bilbit/blog/item/5ed5de16a6f6b412962b43eb.html
ÓÃselectÓï¾ä£¬²éѯÖظ´¼Ç¼
¼ÙÉ裬±íÃûΪ T1 ×Ó¶ÎΪ A,B,C
select count(*) ,A,B,C from T1
group by A,B,C having count(*) > 1
²âÊÔÊý¾Ý£º
A100 &n ......
Ò»¡¢»ù´¡
1¡¢ËµÃ÷£º´´½¨Êý¾Ý¿â
CREATE DATABASE database-name
2¡¢ËµÃ÷£ºÉ¾³ýÊý¾Ý¿â
drop database dbname
3¡¢ËµÃ÷£º±¸·Ýsql server
--- ´´½¨ ±¸·ÝÊý¾ÝµÄ device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- ¿ªÊ¼ ±¸·Ý
BACKUP DATABASE pubs TO testBack
4¡¢Ëµ ......