SQL²Ù×÷È«¼¯
SQL²Ù×÷È«¼¯
ÏÂÁÐÓï¾ä²¿·ÖÊÇMssqlÓï¾ä£¬²»¿ÉÒÔÔÚaccessÖÐʹÓá£
SQL·ÖÀࣺ
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
×îÐ
Ïà¹ØÎĵµ£º
Ó¦ÓóÌÐòͨ¹ýodbc,ado»òado.netÓësql serverÁ¬½Ó,ÎÞÂÛͨ¹ýÄÇÖÖ·½Ê½½øÐÐÁ¬½Ó,ÿһÖÖÁ¬½Ó·½Ê½,Ê×ÏÈÒªÉèÖõÄÊÇÁ¬½Ó´®¡£ÒÔϾÍ˵˵¼¸ÖÖ·½Ê½µÄÁ¬½Ó´®µÄÉèÖãº
ÏÈ˵˵odbcÁ¬½Ó,odbcÈ«³ÆΪ¿ª·ÅʽÊý¾Ý¿âÁ¬½Ó,ÊÇ΢Èí×îÔç·¢²¼µÄÊý¾Ý¿âÁ¬½Ó·½Ê½¡£Á¬½Ó´®¸ñʽÈçÏ£ºdriver={sql server};server=·þÎñÆ÷°²È«Ãû;uid=Óû§Ãû;pwd=ÃÜÂë;databa ......
×î½üÕûÀí³öÀ´µÄ.Èç¹û²»ÍêÈ«µÄ»°Ï£Íû´ó¼Ò²¹³ä.
ÔÚaccessÖУ¬×ª»»Îª´óдµÄsqlº¯ÊýÊÇucase£¬ÔÚsqlserverÖУ¬×ª»»Îª´óдµÄº¯ÊýÊÇupper£»ÔÚaccessÖУ¬×ª»»ÎªÐ¡Ð´µÄº¯ÊýÊÇlcase£¬ÔÚsqlserverÖУ¬×ª»»ÎªÐ¡Ð´µÄº¯ÊýÊÇlower£»ÔÚaccessÖУ¬È¡µ±Ç°Ê±¼äµÄº¯ÊýÊÇnow£¬ÁíÍ⻹ÓÐÒ»¸öÈ¡ÈÕÆÚº¯Êýdate£¬ÔÚsqlserverÖУ¬È¡µ±Ç°µÄº¯ÊýÊÇgetdate ......
SQL°æ±¾Éí·ÝÖ¤¸ñʽÑéÖ¤ 0Ϊ´íÎó£¬1ΪÕýÈ·
CREATE function [dbo].[IsID](@str nvarchar(18),@sex int)--´«ÈëÁ½¸ö±äÁ¿ Éí·ÝÖ¤ºÍÐÔ±ð(ÄÐ1Å®2)
returns bit
as
begin
declare @len int
declare @result bit
--set @result=0
set @len=len(@str)
if(@len!=18 and @len!=15)--³¤¶ÈÊÇ18λ»ò15λ
begin
& ......
´ó¼Ò¶¼ÖªµÀ£¬ÓÃPL/SQLÁ¬½ÓOracle£¬ÊÇÐèÒª°²×°Oracle¿Í»§¶ËÈí¼þµÄ¡£ÓÐûҪÏë¹ý²»°²×°Oracle¿Í»§¶ËÖ±½ÓÁ¬½ÓOracleÄØ£¿
ÆäʵÎÒÒ»Ö±ÏëÕâÑù×ö£¬ÒòΪÕâ¸ö¿Í»§¶ËʵÔÚÌ«ÈÃÈËÌÖÑáÁË£¡£¡£¡²»µ«»á°²×°Ò»¸öJDK£¬¶øÇÒ»¹»á°Ñ×Ô¼º·ÅÔÚ»·¾³±äÁ¿µÄ×îÇ°Ã棬»áÔì³É²»Ð¡µÄÂé·³¡£
&n ......
»úÆ÷Çé¿ö
p4: 2.4
ÄÚ´æ: 1 G
os: windows 2003
Êý¾Ý¿â: ms sql server 2000
Ä¿µÄ: ²éѯÐÔÄܲâÊÔ,±È½ÏÁ½ÖÖ²éѯµÄÐÔÄÜ
SQL²éѯЧÂÊ step by step
-- setp 1.
-- ½¨±í
create table t_userinfo
(
userid int identity(1,1) primary key nonclustered,
nick&nbs ......