Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQL²Ù×÷

QL·ÖÀࣺ
DDL—Êý¾Ý¶¨ÒåÓïÑÔ(CREATE£¬ALTER£¬DROP£¬DECLARE)
DML—Êý¾Ý²Ù×ÝÓïÑÔ(SELECT£¬DELETE£¬UPDATE£¬INSERT)
DCL—Êý¾Ý¿ØÖÆÓïÑÔ(GRANT£¬REVOKE£¬COMMIT£¬ROLLBACK)
Ê×ÏÈ,¼òÒª½éÉÜ»ù´¡Óï¾ä£º
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¡¢ËµÃ÷£º´´½¨Ð±í
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
¸ù¾ÝÒÑÓÐµÄ±í´´½¨ÐÂ±í£º
A£ºcreate table tab_new like tab_old (ʹÓÃ¾É±í´´½¨Ð±í)
B£ºcreate table tab_new as select col1,col2… from tab_old definition only
5¡¢ËµÃ÷£ºÉ¾³ýбídrop table tabname
6¡¢ËµÃ÷£ºÔö¼ÓÒ»¸öÁÐ
Alter table tabname add column col type
×¢£ºÁÐÔö¼Óºó½«²»ÄÜɾ³ý¡£DB2ÖÐÁмÓÉϺóÊý¾ÝÀàÐÍÒ²²»Äܸı䣬ΨһÄܸıäµÄÊÇÔö¼ÓvarcharÀàÐ͵ij¤
¶È¡£
7¡¢ËµÃ÷£ºÌí¼ÓÖ÷¼ü£º Alter table tabname add primary key(col)
˵Ã÷£ºÉ¾³ýÖ÷¼ü£º Alter table tabname drop primary key(col)
8¡¢ËµÃ÷£º´´½¨Ë÷Òý£ºcreate [unique] index idxname on tabname(col….)
ɾ³ýË÷Òý£ºdrop index idxname
×¢£ºË÷ÒýÊDz»¿É¸ü¸ÄµÄ£¬Ïë¸ü¸Ä±ØÐëɾ³ýÖØн¨¡£
9¡¢ËµÃ÷£º´´½¨ÊÓͼ£ºcreate view viewname as select statement
ɾ³ýÊÓͼ£ºdrop view viewname
10¡¢ËµÃ÷£º¼¸¸ö¼òµ¥µÄ»ù±¾µÄsqlÓï¾ä
Ñ¡Ôñ£ºselect * from table1 where ·¶Î§
²åÈ룺insert into table1(field1,field2) values(value1,value2)
ɾ³ý£ºdelete from table1 where ·¶Î§
¸üУºupdate table1 set field1=value1 where ·¶Î§
²éÕÒ£ºselect * from table1 where field1 like ’%value1%’ ---likeµÄÓï·¨ºÜ¾«Ã²é×ÊÁÏ!
ÅÅÐò£ºselect * from table1 order by field1,field2 [desc]
×ÜÊý£ºselect count * as totalcount from table1
ÇóºÍ£ºselect sum(field1) as sumvalue from table1
ƽ¾ù£ºselect avg(field1) as avgvalue from table1
×î´ó£ºselect max(field1) as maxvalue from table1
×îС£ºselect min(field1) as minvalue from table1
11¡¢ËµÃ÷£º¼¸¸ö¸ß¼¶²éѯÔËËã´Ê
A£º UNION ÔËËã·û
UNION ÔËËã·û


Ïà¹ØÎĵµ£º

Linq To Sql½ø½×ϵÁУ¨Ò»£© ´ÓÓ³Éä½²Æð

±¾ÏµÁУ¬»ò¶à»òÉÙ£¬Ö±½Ó»ò¼ä½ÓÒÀÀµÈëÃÅϵÁÐ֪ʶ¡£µ«£¬ÒÀÈ»×·Çó¶ÀÁ¢³ÉÕ¡£Òò±¾ÎÄ×÷ÕßˮƽÓÐÏÞ£¬ÎÄÖдíÎóÄÑÃ⣬¾´Çë¶ÁÕßÖ¸³ö²¢Á½⡣±¾ÏµÁн«»áºÍÈëÃŲ¢´æ¡£
°¸Àý
ij¾ý±»ÑûΪһ³¬ÊÐÉè¼ÆÊý¾Ý¿â£¬ÓÃÀ´´æ´¢Êý¾Ý¡£¸Ã¾ý¸ù¾Ý¸Ã³¬ÊÐÖÐʵ¼Ê³öÏֵĶÔÏó£¬Éè¼ÆÁËCustomer, Employee£¬Order, ProductµÈ±í£¬ÓÃÀ´±£´æÏàÓ¦µÄ¿Í»§£¬Ô±¹¤£¬¶© ......

´´½¨oracle dblink&sql²Ù×÷²»Í¬Êý¾Ý¿âµÄ±í

 
¡¡¡¡Á½Ì¨²»Í¬µÄÊý¾Ý¿â·þÎñÆ÷£¬´Óһ̨Êý¾Ý¿â·þÎñÆ÷µÄÒ»¸öÓû§¶ÁÈ¡Áíһ̨Êý¾Ý¿â·þÎñÆ÷ϵÄij¸öÓû§µÄÊý¾Ý£¬Õâ¸öʱºò¿ÉÒÔʹÓÃdblink¡£
¡¡¡¡ÆäʵdblinkºÍÊý¾Ý¿âÖеÄview²î²»¶à£¬½¨dblinkµÄʱºòÐèÒªÖªµÀ´ý¶ÁÈ¡Êý¾Ý¿âµÄipµØÖ·£¬ssidÒÔ¼°Êý¾Ý¿âÓû§ÃûºÍÃÜÂë¡£
¡¡¡¡´´½¨¿ÉÒÔ²ÉÓÃÁ½ÖÖ·½Ê½£º
¡¡¡¡1¡¢ÒѾ­ÅäÖñ¾µØ·þÎñ
ÒÔÏ ......

SQL datepart º¯ÊýµÄÓÃ

·µ»Ø´ú±íÖ¸¶¨ÈÕÆÚµÄÖ¸¶¨ÈÕÆÚ²¿·ÖµÄÕûÊý¡£
Óï·¨
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ÃüÁî´óÈ«£¨ÖµµÃѧϰµÄ¶«Î÷£©

ÒýÓÃ
show me µÄ SQL SERVERÃüÁî´óÈ«£¨ÖµµÃѧϰµÄ¶«Î÷£©
--Óï ¾ä ¹¦ ÄÜ
--Êý¾Ý²Ù×÷
SELECT --´ÓÊý¾Ý¿â±íÖмìË÷Êý¾ÝÐкÍÁÐ
INSERT --ÏòÊý¾Ý¿â±íÌí¼ÓÐÂÊý¾ÝÐÐ
DELETE --´ÓÊý¾Ý¿â±íÖÐɾ³ýÊý¾ÝÐÐ
UPDATE --¸üÐÂÊý¾Ý¿â±íÖеÄÊý¾Ý
--Êý¾Ý¶¨Òå
CREATE TABLE --´´½¨Ò»¸öÊý¾Ý¿â±í
DROP TABLE --´ÓÊý¾Ý¿âÖÐɾ³ý±í
ALTER T ......

sys.tables£¨sql server 2005£©

Ϊÿ¸ö±í¶ÔÏó·µ»ØÒ»ÐС£µ±Ç°½öÓÃÓÚ sys.objects.type = U µÄ±í¶ÔÏó¡£
ÁÐÃû Êý¾ÝÀàÐÍ ËµÃ÷
<¼Ì³ÐµÄÁÐ>
 
ÓйشËÊÓͼËù¼Ì³ÐµÄÁеÄÁÐ±í£¬Çë²ÎÔÄ sys.objects
lob_data_space_id
int
Ò»¸ö·ÇÁãÖµ£¬ÊDZ£´æ´Ë±íµÄ text¡¢ntext ºÍ image Êý¾ÝµÄ´ÅÅ̿ռ䣨Îļþ×é»ò·ÖÇø¼Ü¹¹£©µÄ ID¡£
0 = ±í²»°üº¬ text¡¢ntext ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ