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

SQLλÔËËã

SQLλÔËËã
select 2|8       --10
select 2|8|1    --11
select 10&8    --8,°üº¬,10=8+2
select 10&2    --2,°üº¬,10=2+8
select 10&4    --0,²»°üº¬
select 19&16  --16,°üº¬,19=16+2+1
select 19&8    --0,°üº¬,19=16+2+1
select * from SqlBitOperation where FBitTags&4=4
 
ÔÚȨÏÞÖеÄÓ¦ÓÃ
1¡¢Á½Õűí
£¨1£©¡¢²Ù×÷ÓëȨÏÞ±êÖ¾±í
if exists (select * from sysobjects where id = OBJECT_ID('[RightTags]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [RightTags]
CREATE TABLE [RightTags] (
[Pkid] [int]  IDENTITY (1, 1)  NOT NULL,
[RightsName] [nvarchar]  (50) NOT NULL,
[RightsTag] [int]  NOT NULL DEFAULT (0))
ALTER TABLE [RightTags] WITH NOCHECK ADD  CONSTRAINT [PK_RightTags] PRIMARY KEY  NONCLUSTERED ( [Pkid] )
SET IDENTITY_INSERT [RightTags] ON
INSERT [RightTags] ([Pkid],[RightsName],[RightsTag]) VALUES ( 1,'³Ô·¹',1)
INSERT [RightTags] ([Pkid],[RightsName],[RightsTag]) VALUES ( 2,'À­Êº',2)
INSERT [RightTags] ([Pkid],[RightsName],[RightsTag]) VALUES ( 3,'´òÅÚ',4)
INSERT [RightTags] ([Pkid],[RightsName],[RightsTag]) VALUES ( 4,'ÅÝæ¤',8)
INSERT [RightTags] ([Pkid],[RightsName],[RightsTag]) VALUES ( 5,'Éú×Ó',16)
INSERT [RightTags] ([Pkid],[RightsName],[RightsTag]) VALUES ( 6,'°ü¶þÄÌ',32)
SET IDENTITY_INSERT [RightTags] OFF

£¨2£©¡¢Óû§ÓëȨÏÞ±í
if exists (select * from sysobjects where id = OBJECT_ID('[RightUsers]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [RightUsers]
CREATE TABLE [RightUsers] (
[Pkid] [int]  IDENTITY (1, 1)  NOT NULL,
[FUser] [nvarchar]  (50) NOT NULL,
[UserRights] [int]  NOT NULL DEFAULT (0))
ALTER TABLE [RightUsers] WITH NOCHECK ADD  CONSTRAINT [PK_RightUsers] PRIMARY KEY  NONCLUSTERED ( [Pkid] )
SET IDENTITY_INSERT [RightUsers] ON
INSERT [RightUsers] ([Pkid],[FUser],[UserRights]) VALUES ( 1


Ïà¹ØÎĵµ£º

SQLÓï¾ä ÁªºÏ²éѯ»¹ÊÇÔÚ²éѯ½á¹ûÖÐǶÌ×

TABLE MASTER   ×Ö¶Î ID DETAIL.....
TABLE BIZ   ×Ö¶Î SYS_ID  CODE_ID .......
²éѯʱÐèÒªµÄÊÇIDµÄÃèÊö
1,SELECT A.SYS_ID,A.CODE_ID,B.DETAIL,C.DETAIL...... from BIZ A,MASTER B,MASTER C WHERE A.SYS_ID=B.ID AND A.CODE_ID=C.ID
2,SELECT SYS_ID,(SELECT DETAIL from MASTER ......

SQL¼¶Áª¸üкͼ¶ÁªÉ¾³ý

alter table ±íÃû
add constraint Ô¼ÊøÃû
foreign key(×Ö¶ÎÃû) references Ö÷±íÃû(×Ö¶ÎÃû)
on delete cascade
Óï·¨£º
Foreign Key
(column[,...n])
references referenced_table_name[(ref_column[,...n])]
[on delete cascade]
[on update cascade]
×¢ÊÍ£º
column:ÁÐÃû
referenced_table_name:Íâ¼ü²Î¿¼µÄÖ÷¼ü± ......

sqlÓï¾ä²éѯ±íµÄ×Ö¶ÎÃû

select name from syscolumns where id in (select id from sysobjects where type = 'u' and name = 'ÏàÓ¦±íÃû')  
ÓÃÒÔÉÏsqlÓï¾äÊäÈëÏàÓ¦±íÃû¾Í¿ÉÒԲ鵽±íµÄ×Ö¶ÎÃû£¬¶ÔÓ¦ºÃÊý¾Ý¿â ²éѯÊÇ·ñ´æÔڸñíÓï¾ä
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tb_cost]') and OBJECTPROPER ......

SQL²éѯÓï¾ä£¨¹ØÓÚÖØ¸´Êý¾ÝµÄ£©

1¡¢²éѯ±íÖÐÖØ¸´Êý¾Ý¡£select * from people
where peopleId in (select  peopleId  from  people  group  by  peopleId  having  count(peopleId) > 1)
2¡¢É¾³ý±íÖжàÓàµÄÖØ¸´¼Ç¼£¬Öظ´¼Ç¼ÊǸù¾Ýµ ......

SQLÖÐÈçºÎÓÃÒ»¸ö±í¸üÐÂÁíÒ»¸ö±í

for ACCESS :
update a, b set a.name=b.name1 where a.id=b.id
for SQL Server:
"update a set a.name=b.name1 from a,b where a.id=b.id"
update   a   set   a.status=b.status  
  from   table1   a,table2   b  
&nbs ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ