SQL SERVERÓï·¨
1.´´½¨±í
(1)ÓÃCreate Table ÃüÁî´´½¨±í
Óï·¨:
Create Table tabl_name
({
}column_name As computed_column_expression
}
}[£¬...n]
)
[On {fiegroup | Default}]
[Textimage_On {fiegroup | Default}]
Àý×Ó:
´ò¿ªcustÊý¾Ý¿â£¬´´½¨Ò»¸ö±í£¬¸Ã±í°üº¬ÁËѧÉúµÄÓйØÐÅÏ¢£¬¼´ÓÐѧºÅ¡¢ÐÕÃû¡¢ÐԱ𡢳öÉúÈÕÆÚ¡¢¼®¹á¡¢ÁªÏµµç»°¡¢×¡Ö·ºÍ±¸×¢ÐÅÏ¢¡£
Use cust
Create Table students
(
number int not null£¬
name varchar(10) not null£¬
sex char(2) null£¬
birthday datetime null£¬
hometown varchar(30) null£¬
telphone_no varchar(12) null£¬
address varchar(30) null£¬
others varchar(50) null
)
ÔÚÕâ¸ö±íÖÐnumber±íʾѧÉú´úºÅ£¬Êý¾ÝÀàÐÍΪint£¬²»ÔÊÐíΪ¿Õ;name±íʾѧÉúÐÕÃû£¬Êý¾ÝÀàÐÍΪvarchar£¬³¤¶ÈΪ10£¬²»ÔÊÐíΪ¿Õ;sex±íʾѧÉúµÄÐÔ±ð£¬Êý¾ÝÀàÐÍΪchar£¬³¤¶ÈΪ2£¬ÔÊÐíΪ¿Õ;birthday±íʾѧÉúµÄ³öÉúÈÕÆÚ£¬Êý¾ÝÀàÐÍΪdatetime£¬ÔÊÐíΪ¿Õ;hometown±íʾѧÉúµÄ¼®¹á£¬Êý¾ÝÀàÐÍΪvarchar£¬³¤¶ÈΪ30£¬ÔÊÐíΪ¿Õ;telephone_no±íʾѧÉúµÄÁªÏµµçÄÔ£¬Êý¾ÝÀàÐÍΪvarchar£¬³¤¶ÈΪ12£¬ÔÊÐíΪ¿Õ;address±íʾѧÉúµÄסַ£¬Êý¾ÝÀàÐÍΪvarchar£¬³¤¶ÈΪ30£¬ÔÊÐíΪ¿Õ;others±íʾѧÉúµÄ±¸×¢ÐÅÏ¢£¬³¤¶ÈΪ50£¬ÔÊÐíΪ¿Õ¡£
2.Ð޸ıíµÄ½á¹¹
(1)ʹÓÃT-SQLÓï¾äÔö¼ÓºÍɾ³ýÒ»¸öÐÂÁÐ
Óï·¨:
Alter Table table
{
ADO
{[]
|colun_name As computed_column_expression
|[]
}[£¬...n]
|Drop
{Column column
}[£¬...n]
}
Àý×Ó:´ò¿ªcustÊý¾Ý¿â£¬ÐÞ¸ÄÆäÖеıístudentsµÄ½á¹¹£¬Ôö¼ÓÒ»¸öÐÂ×ֶΣ¬×Ö¶ÎÃûΪying£¬Êý¾ÝÀàÐÍÊÇvarchar£¬³¤¶ÈÊÇ10£¬Ã»ÓÐĬÈÏÖµ£¬³äÐíΪ¿Õ¡£
Use cust
Alter Table students Add ying varchar(10) null
´ò¿ªcustÊý¾Ý¿â£¬ÐÞ¸ÄÆäÖеıístudentsµÄ½á¹¹£¬É¾³ýÒ»¸ö×ֶΣ¬×Ö¶ÎÃûΪying¡£
Use cust
Alter Table students Drop Column ying
3.Ïò±íÖвåÈëÊý¾Ý
(1)Óà Insert Óï¾ä
Óï·¨ÈçÏÂ:
Insert [Into]
{table_name|view_name}[(column_list)]
{Values|values_list|select_statement}
×¢Òâ:ÔÚ²åÈëÊý¾Ýʱ£¬×Ö·ûÊý¾ÝºÍÈÕÆÚÊý¾ÝҪʹÓÃÒýºÅÒýÆðÀ´¡£
Àý×Ó:
Use cust
Insert Into students
Values (11£¬"Ó°×Ó"£¬"ÄÐ"£¬"1999-12-12"£¬"ºþ±±"£¬"83779805"£¬"Î人ÊÐÇÅ¿ÚÇø"£¬"VB°®ºÃÕß")
´ò¿ªcustÊý¾Ý¿â£¬Ïòstudents±íÖвåÈëÊý¾Ý
(2)ÓÃDefault Ñ¡Ïî
ÔÚ²åÈëÊý¾Ýʱ£
Ïà¹ØÎĵµ£º
bit£º0»ò1µÄÕûÐÍÊý×Ö
int£º´Ó-2^31(-2,147,483,648)µ½2^31(2,147,483,647)µÄÕûÐÍÊý×Ö
smallint£º´Ó-2^15(-32,768)µ½2^15(32,767)µÄÕûÐÍÊý×Ö
tinyint£º´Ó0µ½255µÄÕûÐÍÊý×Ö
decimal£º´Ó-10^38µ½10^38-1µÄ¶¨¾«¶ÈÓëÓÐЧλÊýµÄÊý×Ö
numeric£ºdecimalµÄͬÒå´Ê
money£º´Ó-2^63(-922,337,203,685,477.580 ......
1£¬SqlServer´æ´¢¹ý³ÌµÄÊÂÎñ´¦Àí
Ò»ÖֱȽÏͨÓõijö´í´¦ÀíµÄģʽ´ó¸ÅÈçÏ£º
Create procdure prInsertProducts
(
@intProductId int,
@chvProductName varchar(30),
@intProductCount int
)
AS
Declare @intErrorCode int
Select @intErrorCode=@@Error
Begin transaction
if @intError ......
--> Title : SQL ServerÖ®·Ö²¼Ê½ÊÂÎñ
--> Author : wufeng4552
--> Date : 2009-11-11
SQL ServerÖ®·Ö²¼Ê½ÊÂÎñ
(Ò»)¸ÅÄî:
·Ö²¼Ê½ÊÂÎñÊÇÉæ¼°À´×ÔÁ½¸ö»ò¶à¸öÔ´µÄ×ÊÔ´µÄÊÂÎñ¡£Microsoft® SQL Server™ 2000Ö§³Ö·Ö²¼Ê½ÊÂÎñ£¬Ê¹Óû§µÃÒÔ´´½¨ÊÂÎñÀ´¸üжà¸öSQL ServerÊý¾Ý¿âºÍÆäËüÊý¾ÝÔ ......
ÓÉÓÚ´¦ÓÚϵͳ¿ª·¢µÄºóÆÚ£¬ÐèÒª¸ø¿Í»§ÑÝʾ¡£·¢ÏÖ´óÁ¿µÄ±í£¬´æÔÚ´óÁ¿µÄ²âÊÔÊý¾Ý¡£ÐèÒªÇå³ý£¬ÓÓdelete from tablename” --> ÔÎËÀ¡£ºóÀ´·¢ÏÖ¾ÓÈ»ÓÐÕâôǿ´óµÄ¶«¶«¡£ £º£©
EXECUTE sp_msforeachtable 'delete from ?'
......
½«b±íÖÐcallerÁеÄÖµ²åÈëa±íÖÐcallÁÐÖС£
create table a
(
fid int,
call varchar(20),
age int
)
create table b
(
fid int,
caller varchar(20),
parentId int
)
select * from a
select * from b
insert into a values(1,null,19)
insert into a values(2,n ......