SQL server2005 (database security and referential integrity)

Source: Internet
Author: User
Tags add key sql

--Create Login account

Create login username with password= ' password '

--Create a database user

Create user username for login username

---Grant the user the right to query the student table, as well as to grant it further authorization to other users.

Grant Select

On student

To User_tom

With GRANT option

-----

Create login marry with password= ' marry001 '

Create user User_marry for login marry

--Creating roles

Create role Dbnormuser

---The role authorization

Grant Select

On student

To Dbnormuser

--Specify a fixed server role (login name)

Sp_addsrvrolemember Marry,sysadmin

Delete

Sp_dropsrvrolemember Marry,sysadmin

--View Users

Sp_helpuser

---new FOREIGN KEY constraint

ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES Test_main;

---delete a foreign key

ALTER TABLE test_sub Drop CONSTRAINT main_id_cons

--Create a cascading delete foreign key

ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES Test_main on Delete

Cascade

--Create a cascading update foreign key

ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main on update

Cascade

--Create a delete referenced primary key is the foreign key of the key reference relationship set to NULL

ALTER TABLE test_sub ADD CONSTRAINT main_id_cons FOREIGN KEY (main_id) REFERENCES test_main on update

Set NULL

----Referential integrity

You cannot delete a record with a foreign key



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.