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