SQLServer:GUI方式、SQL语句两种方式建立视图和GUI方式设置主键、约束等

创建视图: GUI Method: In SQL Server Management Studio, connect to the database, expand the database, right-click View and select New View, add tables DEPT01 and EMP01 , select fields and save as DEPT_EMP_VU. SQL statement: CREATE VIEW DEPT_EMP_VU AS SELECT d.Department name, d.Department location, e.Employee name, e.Salary FROM DEPT01 d JOIN EMP01 e ON d.Department ID=e.Department ID;
Set primary key and constraints: GUI Mode: Expand the database, right-click "Table", select "Theme", right-click the field and select "Set Primary Key" and add constraints in the "Foreign Key" or "Check Constraints" tab.
导出SQL脚本: 右键单击数据库或表,选择将表脚本为,选择脚本类型并将其另存为 .sql 文件。

实用提醒:请记住在应用脚本之前先对其进行测试。

sqlserver中,schema的概念

SQL Server Schema is a grouping of database objects, including tables, views, stored procedures, indexes, etc.
Warehouse metaphor: 数据库是一个存储库。
The DB administrator is the warehouse administrator. A schema is a space in the warehouse, and a schema represents a space. 用户是房间管理员,具有表单管理权限,可以管理多个房间,即拥有多个用户对房间的访问权限。

计算机比喻: 桌子是房间里的一个柜子。
立柱是柜子内部的立柱。
Rows是一家橱柜店。
数据是存储在柜子中的对象。

The concepts Schema and Database in MySQL are equivalent, and Sys, User and Dbo are merged into a single dboschema.
请求订单: SQL Server first queries the sys.mytable (system schema), then queries the user's schema, and finally queries the DBO public schema.
MySQL has only one room and all users share the dboschema.

sqlserver中,schema的概念

SQL Server 中的架构是分组的概念。
说白了,就是将数据库中的东西整合到一起,比如表、视图、存储过程、索引等。

Suppose you have a large warehouse where everything is located. The scheme is similar to the small rooms in this warehouse. There are different things in each room, some for clothes, some for food, so they are easy to find and management is clear.
我们来谈谈用户和权限。
In SQL Server, users can have administrative rights to a specific schema, which is equivalent to being the administrator of a specific room. One user can manage multiple rooms, making data access control much more flexible.
还有查询顺序,很有趣。
When SQL Server runs a query, it looks for objects in the schema in turn.首先检查系统架构,然后检查用户默认架构,最后检查公共架构。
这样,对象访问高效且定位精确。

Compared to MySQL, it is completely different. In MySQL, schema and database are two different things.说白了,每个MySQL数据库就相当于一个大仓库,里面有一个房间,所有用户共享这个空间。
但SQLServer 不同。
它允许您在同一数据库中创建多个模式,因此数据组织和管理更加精细。