SQL 2005 CHECKÔ¼ÊøºÍ¹æÔòÇø±ð
Ò»¡¢Ô¼Êø
Ô¼Êø¶¨Òå¹ØÓÚÁÐÖÐÔÊÐíÖµµÄ¹æÔò£¬ÊÇÇ¿ÖÆÍêÕûÐԵıê×¼»úÖÆ¡£
ʹÓÃÔ¼ÊøÓÅÏÈÓÚʹÓô¥·¢Æ÷¡¢¹æÔòºÍĬÈÏÖµ¡£²éѯÓÅ»¯Æ÷ҲʹÓÃÔ¼Êø¶¨ÒåÉú³É¸ßÐÔÄܵIJéѯִÐмƻ®¡£SQL Server 2005Ö§³ÖÎåÀàÔ¼Êø£º
1. NOT NULLÖ¸¶¨²»½ÓÊÜNULLÖµµÄÁС£
2. CHECK Ô¼Êø¶Ô¿ÉÒÔ·ÅÈëÁÐÖеÄÖµ½øÐÐÏÞÖÆ£¬ÒÔÇ¿ÖÆÖ´ÐÐÓòµÄÍêÕûÐÔ¡£CHECKÔ¼Êø¾Ü¾øËùÓÐÔÚ¼ì²âÌõ¼þÖÐȡֵΪfalseµÄÖµ¡£¿ÉÒÔΪÿÁÐÖ¸¶¨¶à¸öCHECKÔ¼Êø¡£ÏÂÀýÏÔʾÃûΪchk_idÔ¼ÊøµÄ´´½¨£¬¸ÃÔ¼ÊøÈ·±£Ö»¶Ô´Ë¹Ø¼ü×ÖÊäÈëÖ¸¶¨·¶Î§ÄÚµÄÊý×Ö£¬ÒÔ½øÒ»²½Ç¿ÖÆÖ´ÐÐÖ÷¼üµÄÓò¡£
CREATE TABLE cust_sample
(
cust_id int PRIMARY KEY,
cust_name char(50),
cust_address char(50),
cust_credit_limit money,
CONSTRAINT chk_id CHECK(cust_id BETWEEN 0 and 10000)
)
3. UNIQUEÔ¼Êø£º¶ÔÓÚ UNIQUE Ô¼ÊøÖеÄÁУ¬±íÖв»ÔÊÐíÓÐÁ½Ðаüº¬ÏàͬµÄ·Ç¿ÕÖµ¡£Ö÷¼üҲǿÖÆÖ´ÐÐΨһÐÔ£¬µ«Ö÷¼ü²»ÔÊÐí¿ÕÖµ¡£UNIQUE Ô¼ÊøÓÅÏÈÓÚΨһË÷Òý¡£
4. PRIMARY KEY Ô¼Êø±êʶÁлòÁм¯£¬ÕâЩÁлòÁм¯µÄֵΨһ±êʶ±íÖеÄÐС£ÔÚÒ»¸ö±íÖУ¬²»ÄÜÓÐÁ½Ðаüº¬ÏàͬµÄÖ÷¼üÖµ¡£²»ÄÜÔÚÖ÷¼üÄÚµÄÈκÎÁÐÖÐÊäÈëNULLÖµ¡£ÔÚÊý¾Ý¿âÖÐNULLÊÇÌØÊâÖµ£¬´ú±í²»Í¬Óڿհ׺Í0ÖµµÄδֵ֪¡£½¨ÒéʹÓÃÒ»¸öСµÄÕûÊýÁÐ×÷ΪÖ÷¼ü¡£Ã¿¸ö±í¶¼Ó¦ÓÐÒ»¸öÖ÷¼ü¡£
Ò»¸ö±íÖпÉÒÔÓÐÒ»¸öÒÔÉϵÄÁÐ×éºÏ£¬ÕâЩ×éºÏÄÜΨһ±êʶ±íÖеÄÐУ¬Ã¿¸ö×éºÏ¾ÍÊÇÒ»¸öºòÑ¡¼ü¡£Êý¾Ý¿â¹ÜÀíÔ±´ÓºòÑ¡¼üÖÐÑ¡ÔñÒ»¸ö×÷ΪÖ÷¼ü¡£ÀýÈ磬ÔÚpart_sample±íÖУ¬part_nmbrºÍpart_name¶¼¿ÉÒÔÊǺòÑ¡¼ü£¬µ«ÊÇÖ»½«part_nmbrÑ¡×÷Ö÷¼ü¡£
CREATE TABLE part_sample
(
 
Ïà¹ØÎĵµ£º
Êý¾Ý¿â¿ª·¢¹ý³ÌÖУ¬µ±Äã¼ìË÷µÄÊý¾ÝÖ»ÊÇÒ»Ìõ¼Ç¼ʱ£¬ÄãËù±àдµÄÊÂÎñÓï¾ä´úÂëÍùÍùʹÓÃSELECT INSERT Óï¾ä¡£µ«ÊÇÎÒÃdz£³£»áÓöµ½ÕâÑùÇé¿ö£¬¼´´Óijһ½á¹û¼¯ÖÐÖðÒ»µØ¶ÁÈ¡Ò»Ìõ¼Ç¼¡£ÄÇôÈçºÎ½â¾öÕâÖÖÎÊÌâÄØ£¿ÓαêΪÎÒÃÇÌṩÁËÒ»ÖÖ¼«ÎªÓÅÐãµÄ½â¾ö·½°¸¡£
1.1 ÓαêºÍÓαêµÄÓŵã
& ......
declare @p int
declare @p1 int
declare @count int
set @p=0
set @p1=10
set @count=2
if(@count<>0 or @count<>1)
set @p=@p1*@count-10
SELECT [t1].[userid], [t1].[username], [t1].[userorder]
from (
SELECT ROW_NUMBER() OVER (ORDER BY [t0].[userorder]) AS [ROW_NU ......
#ÐÂÔöÒ»¸ö×ֶΣ¬Ä¬ÈÏֵΪ0£¬·Ç¿Õ£¬×Ô¶¯Ôö³¤£¬Ö÷¼ü
alter table tabelname add new_field_name field_type default 0 not null auto_increment ,add primary key (new_field_name);
#Ôö¼ÓÒ»¸öÐÂ×Ö¶Î
alter table tableName add new_field_name field_type;
alter table tableNam ......
1. ¸´ÖƱí½á¹¹
Sql´úÂë
1. select * into B from A where 1=0;
select * into B from A where 1=0;
2.¸´ÖƱí¼Ç¼ ¸´ÖÆijЩ×Ö¶Î
Sql´úÂë
1. insert into B(a, b, c) select d, e, f from A;
insert into B(a, b, c) select d, e, f from A;
¸´Ö ......