Hướng dẫn cách tạo sơ đồ quan hệ sql create năm 2024

Hãy nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, bản cập nhật bảo mật và hỗ trợ kỹ thuật.

Create a database schema

  • Bài viết
  • 08/01/2023

Trong bài viết này

Applies to:

This article describes how to create a schema in SQL Server by using SQL Server Management Studio or Transact-SQL.

Limitations and Restrictions

  • The new schema is owned by one of the following database-level principals: database user, database role, or application role. Objects created within a schema are owned by the owner of the schema, and have a NULL principal_id in sys.objects. Ownership of schema-contained objects can be transferred to any database-level principal, but the schema owner always retains CONTROL permission on objects within the schema.
  • When creating a database object, if you specify a valid domain principal (user or group) as the object owner, the domain principal is added to the database as a schema. The new schema is owned by that domain principal.

Permissions

  • Requires CREATE SCHEMA permission on the database.
  • To specify another user as the owner of the schema being created, the caller must have IMPERSONATE permission on that user. If a database role is specified as the owner, the caller must meet one of the following criteria: membership in the role or ALTER permission on the role.

Using SQL Server Management Studio to create a schema

  1. In Object Explorer, expand the Databases folder.
  2. Expand the database in which to create the new database schema.
  3. Right-click the Security folder, point to New, and select Schema.
  4. In the Schema - New dialog box, on the General page, enter a name for the new schema in the Schema name box.
  5. In the Schema owner box, enter the name of a database user or role to own the schema. Alternately, select Search to open the Search Roles and Users dialog box.
  6. Select OK.

Note

A dialog box will not appear if you are creating a Schema using SSMS against an Azure SQL Database or an Azure Synapse Analytics. You will need to run the Create Schema Template T-SQL Statement that is generated.

Additional Options

The Schema - New dialog box also offers options on two additional pages: Permissions and Extended Properties.

  • The Permissions page lists all possible securables and the permissions on those securables that can be granted to the login.
  • The Extended properties page allows you to add custom properties to database users.

Using Transact-SQL to create a schema

  1. In Object Explorer, connect to an instance of Database Engine.
  2. On the Standard bar, select New Query.
  3. The following example creates a schema named Chains, and then creates a table named Sizes.

    CREATE SCHEMA Chains; GO CREATE TABLE Chains.Sizes (ChainID int, width dec(10,2));

Additional options can be performed in a single statement. The following example creates the schema Sprockets owned by Joe that contains the table NineProngs. The statement grants SELECT to Bob and denies SELECT to

CREATE SCHEMA Sprockets AUTHORIZATION Joe  
    CREATE TABLE NineProngs (source int, cost int, partnumber int)  
    GRANT SELECT ON SCHEMA::Sprockets TO Bob  
    DENY SELECT ON SCHEMA::Sprockets TO John;  
GO  

1.

MySQL Workbench là một công cụ truy cập cơ sở dữ liệu được mô hình hóa và thiết kế trực quan sử dụng cho cơ sở dữ liệu quan hệ MySQL server. MySQL Workbench giúp tạo ra các mô hình dữ liệu vật lý mới và hỗ trợ sửa đổi các cơ sở dữ liệu MySQL hiện có với các kỹ thuật đảo ngược / chuyển tiếp, các chức năng quản lý tùy chọn.

Để cài đặt MySQL Workbench thì hơi nhiều bước chút xíu nên mình không nói ở đây, các bạn có thể vào đây để tham khảo nhé. Từ cài đặt rồi cho đến kết nối với MySQL luôn, giờ thì ta bắt đầu tạo nào.

Tạo ER Diagram

1. Đầu tiên bạn phải chắc chắn có Database và Tables được tạo trên MySQL server.

Ở đây mình đã kết nối và chuẩn bị sẵn một database như sau:

Database - report

Tables - migrations, users, passwordresets, products, categories, images, categoryproduct

2. Click Database -> Reverse Engineer.

3. Tại cột Stored Connection chọn database từ danh sách thả xuống, sau đó chọn Next

Nếu bạn nhận được thông báo nhập mật khẩu thì hãy nhập mật khẩu phpMyadmin của bạn vào nhé.

4. Sau khi kết nối thành công (connection to DBMS), tiếp chọn chọn Next.

5. Chọn Database mà bạn muốn tạo ER Diagram (ở đây của mình là "report"), sau đó chọn Next.

6. Tiếp tục chọn Next.

7. Cuối cùng chọn Execute -> Next -> Close.

8. ER Diagram của Database.

Giờ thì bạn đã có được lược đồ Diagram cho Database của bạn rồi đó, bạn chỉ cần Export ra file .png rồi nộp cho giáo viên thôi.

Kết luận

Vừa rồi mình đã hướng dẫn các bạn tạo ER Diagram bằng MySQL Workbench rồi đó, thật đơn giản phải không. Qua bài này mình mong giúp được chút ít cho các bạn muốn tạo ER Diagram từ Database, không còn phải ngồi thủ công như trước nữa. Tuy nhiên bạn cũng có thể di chuyển các bảng theo vị trí mình thích nhé, và còn cách nào thì các bạn cũng comment để cho mình và các bạn cùng biết.

Cảm ơn các bạn đã đọc bài của mình, hãy upvote cho mình để mình có động lực viết các bài tiếp theo nhé

Hướng dẫn cách tạo sơ đồ quan hệ sql create năm 2024

Bài viết tham khảo

https://medium.com/@tushar0618/how-to-create-er-diagram-of-a-database-in-mysql-workbench-209fbf63fd03