Search code examples
sql-server

What exactly is database schema?


So in this link, I found multiple answers which one is correct? What is the purpose of database schema?

I found this. What's confusing for me I think is that they both definitions are different from each other Guide me..

  1. A SQL schema is container of objects. For example, you may have a large enterprise application and then it's a good practice to use different schemas for different purposes (e.g. put HR related tables into HR schema, accounting related tables into Accounting schema and so on). A schema can be owned by any user, and the ownership is transferable.

  2. The database schema is the definition that describes the entire configuration of the database, including all of its tables, relations, index, etc

My question is different I have read the multiple answers which are available but I found multiple answers that is what made me more confused.


Solution

  • Both are correct. "Schema" has multiple meanings. Your first meaning is the kind of schema you get with CREATE SCHEMA -- an object container. Your second meaning is the general meaning of "database schema" that's independent of SQL Server. Usually it's clear from context which meaning is intended -- "database schema" is typically singular, while "schemas" within a single database refer to the containers. So, if you wanted to be particularly confusing, you could talk about a database schema2 that has multiple schemas1 in it.