SQLServer2005新建用户

Standard
CREATE login testuser WITH password='123456'
USE mytest
CREATE USER testuser FOR login testuser

点击 mytest->安全性->用户。
双击testuser,在出现的界面右中”拥有的架构”,右下”角色成员”中都选上db_owner.
至此,建立的用户就成了该数据库的管理员了.

SQLServer无法连接到服务器用户xxx登陆失败的解决方法

Standard

“无法连接到服务器,用户xxx登陆失败”
该错误产生的原因是由于SQL Server使用了”仅 Windows”的身份验证方式,
因此用户无法使用SQL Server的登录帐户(如 sa )进行连接.解决方法如下所示:

1.使用企业管理器,展开”SQL Server组”
2.鼠标右键点击SQL Server服务器的名称,选择”属性”
3.选择”安全性”选项卡,在”身份验证”下,选择”SQL Server和 Windows “,”确定”
4.重新启动SQL Server服务.

有时点了确定后仍然不生效,那就通过修改注册表来解决此问题:

1.点击”开始””运行”,输入regedit,回车进入注册表编辑器
2.依次展开注册表项,浏览到以下注册表键:
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSSQLServer\MSSQLServer]
3.在屏幕右方找到名称”LoginMode”,双击编辑双字节值
4.将原值从1改为2,点击”确定”
5.关闭注册表编辑器
6.重新启动SQL Server服务.

SQLServer的@@IDENTITY和Mysql的LAST_INSERT_ID()

Standard

CREATE PROCEDURE NewWeekPlan
@file_type numeric(1),
@file_department varchar(50),
@file_station varchar(50),
@file_owner numeric(9),

@weekplan_wk1plan varchar(255),
@weekplan_wk2plan varchar(255),
@weekplan_wk3plan varchar(255),
@weekplan_wk4plan varchar(255),
@weekplan_wk5plan varchar(255),
@weekplan_wk1result varchar(255),
@weekplan_wk2result varchar(255),
@weekplan_wk3result varchar(255),
@weekplan_wk4result varchar(255),
@weekplan_wk5result varchar(255),
@weekplan_wk1plannext varchar(255),
@weekplan_wk2plannext varchar(255),
@weekplan_wk3plannext varchar(255),
@weekplan_wk4plannext varchar(255),
@weekplan_wk5plannext varchar(255),
@weekplan_problem1 varchar(255),
@weekplan_problem2 varchar(255),
@weekplan_problem3 varchar(255),
@weekplan_suggest1 varchar(255),
@weekplan_suggest2 varchar(255),
@weekplan_suggest3 varchar(255)

AS INSERT INTO tb_file (file_type,file_department,file_station,file_owner) VALUES (@file_type,@file_department,@file_station,@file_owner)
if @@IDENTITY>0
INSERT INTO tb_file_weekplan (weekplan_file,weekplan_wk1plan,weekplan_wk2plan,weekplan_wk3plan,weekplan_wk4plan,weekplan_wk5plan) VALUES (@@IDENTITY,@weekplan_wk1plan,@weekplan_wk2plan,@weekplan_wk3plan,@weekplan_wk4plan,@weekplan_wk5plan)
GO

//———————-yemaosheng.com——————————–
用 last_insert_id() 函数这样来模拟一个 sequence 实现:

mysql> CREATE TABLE sequence (id INT NOT NULL);
mysql> INSERT INTO sequence VALUES (0);

mysql> UPDATE sequence SET id=LAST_INSERT_ID(id+1);