sqlserver security and integrity, to speak with Case
User / Role created
Statement creates
sp_addlogin '王二','123456' ; //创建用户
//sp_addlogin'登录名','密码';
sp_addrole r1; //创建角色
Create a tool
to create a user
to create roles
Set constraints
The only constraint is defined in the "course name" curriculum field.
CREATE TABLE Cource (
CNo char(3) not null primary key,
CName varchar(30) unique ,
PreCource char (3) ,
Grade int
)
Elective check constraint is defined on the table "score" field, so that it must be greater than 0 and less than or equal to 100. "Course Number" field can only enter numeric characters.
CREATE TABLE sc (
SNo int not null ,
CNo int not null check(cno like '[0-9][0-9][0-9]'),
grade int check(grade>=0 and grade<=100),
primary key(sno,cno) ,
foreign key(CNo) references Cource(CNo),
foreign key(SNo) references Student(SNo)
)
Defining integrity constraints named clause, restrict student table "gender" field so that it can only take "male and female" value.
CREATE TABLE student1 (
SNo char (9) PRIMARY key ,
SName varchar (10) ,
SSex char (2) check(ssex in('男','女')),
SAge int NULL ,
SDept char (10) ,
)
Increase in the student table date of birth field and define integrity constraints named clause, the default value date of birth to take the current date.
alter table Student add Birthday datetime default getdate();
Permission granted
In the windows sa account or accounts
grant select,update on Student to 王二