易截截图软件、单文件、免安装、纯绿色、仅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语句查询表的字段名

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随机查询

SQL Server:
Select TOP N * from TABLE Order By NewID()  
Select TOP N * from TABLE Order By NewID()
NewID()函数将创建一个 uniqueidentifier 类型的唯一值。上面的语句实现效果是从Table中随机读取N条记录。
Access:
Select TOP N *&n ......

sql查询优化


1、    用程序中,保证在实现功能的基础上,尽量减少对数据库的访问次数;通过搜索参数,尽量减少对表的访问行数,最小化结果集,从而减轻网络负担;能够分开的操作尽量分开处理,提高每次的响应速度;在数据窗口使用SQL时,尽量把使用的索引放在选择的首列;算法的结构尽量简单;在查询时,不要过多地使用 ......

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号