|
SQL Server 2005, 2008, 2012, 2014, 2016 Create Login / Create User / Database |
SQL Server 2005, 2008, 2012, 2014, 2016 Create Login/Create User/Database Permissions เป็นบทความของ SQL Server ในการสร้าง Create User หรือ User Login รวมทั้งการกำหนดสิทธิ์ของ User ในระดับ Database และระดับ Table ในการเข้าใช้งาน เช่นการกำหนดสิทธิ์ในการ SELECT, INSERT, UPDATE, DELETE รวมทั้งสิทธิ์อื่น ๆ ในการเรียกใช้งาน Database
สำหรับบทความนี้สามารถใช้ได้ทั้ง SQL Server 2005 , SQL Server 2008 , SQL Server 2012 , SQL Server 2014 และ SQL Server 2016

SQL Server Database เป็นฐานข้อมูลขนาดกลางถึงใหญ่ที่มีระบบการจัดการ Permissions ของ User หรือแบ่งสิทธิ์การใช้งานของ User ได้อย่างมีระบบและมีประสิทธิภาพ สามารถกำหนดสิทธิ์ได้ในระดับประเภทของผู้ใช้ หรือสามารถกำหนดสิทธิ์ใน Database หรือจะกำหนดในระดับที่จะสามารถเข้าใช้งาน Table สิทธิ์ในการ Access ของแต่ล่ะ Table ได้เช่นเดียวกัน เช่นใน Database ก้อน ๆ หนึ่งซึ่งมีผู้ใช้อยู่ 4-5 คน เราสามารถกำหนด User แต่ละคนนั้นว่าสามารถเข้าใจงานตารางใดบ้าง และเมื่อ Login เข้าไปแล้วจะสามารถเข้าไปทำอะไรได้บ้าง เช่น บาง User อาจจะแค่ SELECT ข้อมูลเพื่อดูข้อมูลเท่านั้น หรือบางคนสามารถ INSERT ได้ หรือ UPDATE ได้แต่ไม่สามารถ DELETE ได้ ก็สามารถทำได้เช่นเดียวกัน ซึ่งสิทธิ์เหล่านี้จะมีผลทั้งการใช้งานในโปรแกรม SQL Server Management Studio หรือ Tool อื่น ๆ ที่สามารถเชื่อมต่อเรียกใช้งานกับ SQL Server Database ได้ หรือแม้กระทั้งการเรียกจากโปรแกรมอื่น ๆ เช่น ASP , PHP หรือ .NET ผ่าน Connection ต่าง ๆ ที่ได้สร้างขึ้น
จากบทความ
Go to : SQL Server 2005 Authentication Mode
Go to : SQL Server 2008 Authentication Mode
Go to : SQL Server 2012 Authentication Mode
ในการเข้าใช้งานเพื่อสร้างสิทธิ์ของผู้ใช้ ให้ Login ด้วย sa (system admin)

Login ด้วย User ชื่อ sa

ในส่วนของ Object Explorer ให้เลือก Security -> Logins จากนั้นให้คลิกขวาให้เลือก New Login...


ในส่วนของ Login - New ส่วนของ General ให้กรอก Login name พร้อมทั้ง Password ในการ Login (ดูตัวอย่างดังในรูป)

ในส่วนของ User Mapping ให้เลือก Database ที่จะให้ User นี้สามารถเข้าใช้งานได้ พร้อมกับ Database role ของ User ให้เลือกเป็นดังรูป

ในส่วนของ Status -> Permission to connect to database engine : ให้เลือก Grant และ Login เป็น Enabled ตามลำดับ เมื่อเสร็จแล้วให้คลิกที่ OK

ในกรณีที่ต้องการปรับแต่งค่าอื่น ๆ ของ User สามารถคลิกวาที่ User และเลือก Properties ดังรูป

ขั้นตอนถัดไปจะเป็นการปรับแต่ง Login or Roles และสิทธิ์ Permissions ของ User โดยคลิกวาที่ Database Instance -> Properties ดังรูป

ในส่วนของ Permissions -> Permission to myuser : จะเป็นการกำหนดสิทธิ์ของ User ว่าสามารถทำอะไรได้บ้าง เช่น Connect SQL หรือถ้าจะยอมให้มีการสร้างฐานข้อมูลได้ ก็ให้คลิกเลือก Create any database

เมื่อสร้าง Login User เรียบร้อยแล้วให้ Disconnect ผู้ใช้ sa เพื่อจะทำการทดาอบ myuser ที่ได้จากการสร้างขึ้นมาใหม่ โดยคลิกวาที่ Database Instance -> Disconnect

คลิกที่ Connect -> Database Engine

กรอก Login Name และ Password ที่ได้จากการสร้างในขั้นตอนก่อนหน้านี้

เมื่อ Login ผ่านก็จะแสดง Database ที่ Login คนนี้มีสิทธิ์ใช้งาน แต่จะเห็นว่าเนื่องจากสิทธิ์ของ User เป็นแค่ public จึงไม่มีสิทธิ์ในการใช้งาน Object อื่น ๆ โดยสามารถกำหนดสิทธิ์อื่น ๆ โดยการ Login ชื่อผู้ใช้ sa และกลับไปกำหนดสิทธิ์อีกครั้ง
กลับมายังหน้าจอในส่วนของ Login ของ sa

Login ภายใต้ผู้ใช้ sa

ตัวอย่างนี้จะเป็นการกำหนดสิทธิ์ในตารางชื่อ customer โดยให้คลิกที่ Table นั้น ๆ และเลือก Properties

คลิกที่เมนู Permissions ตามด้วยปุ่ม Search

ใส่ชื่อผู้ใช้ที่ได้จากการสร้าง หรือจะ Browse เพื่อดูรายชื่อผู้ใช้ทั้งหมด

หน้าจอในการกำหนดสิทธิ์ของตารางนั้น ๆ ว่าจะให้ผู้ใช้หรือ Login user ที่กำหนดสิทธิ์นั้นสามารถทำอะไรกับตารางได้ เช่น INSERT , SELECT , .....
กลับมายังหน้าจอในส่วนของ Login ของ myuser

Login ภายใต้ผู้ใช้ myuser ที่ได้จากการสร้างในขั้นตอนก่อนหน้านี้

เมื่อดูที่ Database -> Table ก็จะพบกับ Table ที่ได้กำหนดสิทธิ์ในขั้นตอนก่อนหน้านี้

ทดสอบการ Query ข้อมูลโดย Login user จะสามารถใช้งาน Table ตามสิทธิ์ที่ตัวเองมีเท่านั้น
บทความอื่น ๆ ที่เกี่ยวข้อง
Go to : SQL Server 2008 Tutorial
Go to : SQL Server 2005 Authentication Mode
Go to : SQL Server 2005 Tutorial
Go to : SQL Server 2008 Authentication Mode
Go to : SQL Server 2012 Tutorial
Go to : SQL Server 2012 Authentication Mode
|
|
|
By : |
TC Admin
|
|
Article : |
บทความเป็นการเขียนโดยสมาชิก หากมีปัญหาเรื่องลิขสิทธิ์ กรุณาแจ้งให้ทาง webmaster ทราบด้วยครับ |
|
Score Rating : |
   |
|
Create Date : |
2011-08-24 |
|
Download : |
No files |
|
Sponsored Links |
|
|
|
|
|
|