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

²Ù×÷Êý¾Ý¿â½á¹¹µÄ³£ÓÃSqlÃüÁî(2)

²Ù×÷Êý¾Ý¿â½á¹¹µÄ³£ÓÃSql
ÏÂÃæÊÇSql Server ºÍ Access ²Ù×÷Êý¾Ý¿â½á¹¹µÄ³£ÓÃSql£¬ÄÚÈÝÓɺ£ÍÞÕûÀí£¬²»ÕýÈ·Óë²»ÍêÕûÖ®´¦»¹ÇëÌá³ö£¬Ð»Ð»¡£
н¨±í£º
create table [±íÃû]
(
[×Ô¶¯±àºÅ×Ö¶Î] int IDENTITY (1,1)  PRIMARY KEY ,
[×Ö¶Î1] nVarChar(50) default 'ĬÈÏÖµ' null ,
[×Ö¶Î2] ntext null ,
[×Ö¶Î3] datetime,
[×Ö¶Î4] money null ,
[×Ö¶Î5] int default 0,
[×Ö¶Î6] Decimal (12,4) default 0,
[×Ö¶Î7] image null ,
)
ɾ³ý±í£º
Drop table [±íÃû]
²åÈëÊý¾Ý£º
INSERT INTO [±íÃû] (×Ö¶Î1,×Ö¶Î2) VALUES (100,'51WINDOWS.NET')
ɾ³ýÊý¾Ý£º
DELETE from [±íÃû] WHERE [×Ö¶ÎÃû]>100
¸üÐÂÊý¾Ý£º
UPDATE [±íÃû] SET [×Ö¶Î1] = 200,[×Ö¶Î2] = '51WINDOWS.NET' WHERE [×Ö¶ÎÈý] = 'HAIWA'
ÐÂÔö×ֶΣº
ALTER TABLE [±íÃû] ADD [×Ö¶ÎÃû] NVARCHAR (50) NULL
ɾ³ý×ֶΣº
ALTER TABLE [±íÃû] DROP COLUMN [×Ö¶ÎÃû]
ÐÞ¸Ä×ֶΣº
ALTER TABLE [±íÃû] ALTER COLUMN [×Ö¶ÎÃû] NVARCHAR (50) NULL
ÖØÃüÃû±í£º(Access ÖØÃüÃû±í£¬Çë²Î¿¼ÎÄÕ£ºÔÚAccessÊý¾Ý¿âÖÐÖØÃüÃû±í)
sp_rename '±íÃû', 'бíÃû', 'OBJECT'
 
ÖØÃüÃû×Ö¶Î
exec sp_rename '±íÃû.¾É×Ö¶ÎÃû','ÐÂ×Ö¶ÎÃû' [,'column']
н¨Ô¼Êø£º
ALTER TABLE [±íÃû] ADD CONSTRAINT Ô¼ÊøÃû CHECK ([Ô¼Êø×Ö¶Î] <= '2000-1-1')
ɾ³ýÔ¼Êø£º
ALTER TABLE [±íÃû] DROP CONSTRAINT Ô¼ÊøÃû
н¨Ä¬ÈÏÖµ
ALTER TABLE [±íÃû] ADD CONSTRAINT ĬÈÏÖµÃû DEFAULT '51WINDOWS.NET' FOR [×Ö¶ÎÃû]
ɾ³ýĬÈÏÖµ
ALTER TABLE [±íÃû] DROP CONSTRAINT ĬÈÏÖµÃû
ɾ³ýSql Server ÖеÄÈÕÖ¾£¬¼õСÊý¾Ý¿âÎļþ´óС
dump transaction Êý¾Ý¿âÃû with no_log
backup log Êý¾Ý¿âÃû with no_log
dbcc shrinkdatabase(Êý¾Ý¿âÃû)
exec sp_dboption 'Êý¾Ý¿âÃû', 'autoshrink', 'true'


Ïà¹ØÎĵµ£º

PHP SQL ×¢Èë¹¥»÷µÄ¼¼ÊõʵÏÖÒÔ¼°Ô¤·À°ì·¨

¡¡×î½üÔÚÕÛÌÚ PHP + MYSQL
µÄ±à³Ì¡£Á˽âÁËһЩ PHP SQL ×¢Èë¹¥»÷
µÄ֪ʶ£¬ÓÚÊÇдÁËÕâƪÎÄÕ¡¡http://www.xiaohui.com/weekly/20070314.htm£¬×ܽáһϾ­Ñé¡£ÔÚÎÒ¿´À´£¬Òý·¢ SQL ×¢Èë¹¥»÷
µÄÖ÷ÒªÔ­Òò£¬ÊÇÒòΪÒÔÏÂÁ½µãÔ­Òò£º
¡¡¡¡1. php ÅäÖÃÎļþ php.ini ÖÐµÄ magic_quotes_gpc
Ñ¡ÏîûÓдò¿ª£¬±»ÖÃΪ off
¡¡¡¡2. ¿ª·¢ ......

SQLËø±íÓï¾ä(ת)

Ëø¶¨Êý¾Ý¿âµÄÒ»¸ö±í
SELECT * from table WITH (HOLDLOCK)
×¢Òâ: Ëø¶¨Êý¾Ý¿âµÄÒ»¸ö±íµÄÇø±ð
SELECT * from table WITH (HOLDLOCK)
ÆäËûÊÂÎñ¿ÉÒÔ¶ÁÈ¡±í£¬µ«²»ÄܸüÐÂɾ³ý
SELECT * from table WITH (TABLOCKX)
ÆäËûÊÂÎñ²»ÄܶÁÈ¡±í,¸üкÍɾ³ý
SELECT Óï¾äÖГ¼ÓËøÑ¡ÏŦÄÜ˵Ã÷
SQL ServerÌṩÁËÇ¿´ó¶øÍ ......

sql server²éѯµ¼ÈëEXCEL


insert into OPENROWSET('MICROSOFT.JET.OLEDB.4.0'
,'Excel 8.0;HDR=YES;DATABASE=c:\test.xls',sheet1$)
select * from ±íÃû
Èç¹ûÊÇÉú³Éexcel時ÓÃbcp
--µ¼³ö²éѯµÄÇé¿ö
EXEC master..xp_cmdshell 'bcp "SELECT au_fname, au_lname from pubs..authors ORDER BY au_lname" queryout "c:\test.xls" /c -/S"·þÎ ......

½«ExcelµÄÊý¾Ýµ¼Èëµ½SQL 2005ÏÖÓеıíÖÐ

ÎÒÔÚ½«ExcelµÄÊý¾Ýµ¼Èëµ½SQLµÄʱºòÀÏÊdzöÏÖÏÂÃæµÄ´íÎó£º
ÅäÖÃÑ¡Ïî 'show advanced options' ÒÑ´Ó 1 ¸ü¸ÄΪ 1¡£ÇëÔËÐÐ RECONFIGURE Óï¾ä½øÐа²×°¡£
ÅäÖÃÑ¡Ïî 'Ad Hoc Distributed Queries' ÒÑ´Ó 1 ¸ü¸ÄΪ 1¡£ÇëÔËÐÐ RECONFIGURE Óï¾ä½øÐа²×°¡£
ÏûÏ¢ 7399£¬¼¶±ð 16£¬×´Ì¬ 1£¬µÚ 1 ÐÐ
Á´½Ó·þÎñÆ÷ "(null)" µÄ OLE DB ·ÃÎÊ ......

sqlµÄ INNER JOIN, left join,right joinÓï·¨

inner join(µÈÖµÁ¬½Ó) Ö»·µ»ØÁ½¸ö±íÖÐÁª½á×Ö¶ÎÏàµÈµÄÐÐ
left join(×óÁª½Ó) ·µ»Ø°üÀ¨×ó±íÖеÄËùÓмǼºÍÓÒ±íÖÐÁª½á×Ö¶ÎÏàµÈµÄ¼Ç¼
right join(ÓÒÁª½Ó) ·µ»Ø°üÀ¨ÓÒ±íÖеÄËùÓмǼºÍ×ó±íÖÐÁª½á×Ö¶ÎÏàµÈµÄ¼Ç¼
INNER JOIN Óï·¨£º
INNER JOIN Á¬½ÓÁ½¸öÊý¾Ý±íµÄÓ÷¨£º
SELECT * from ±í1 INNER JOIN ±í2 ON ±í1.×ֶκÅ=±í2 ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ