How to create schema in sql server
In this post, I will explain about How to create schema in sql server with an example.
A schema is a bunch of database objects like views, triggers, tables, stored procedures, indexes, etc. A schema is attached with a username which is also called as the schema owner, who is the owner of the logically related database objects.
Built-in schemas in SQL Server
SQL Server provides some pre-defined schemas which have the same names as the built-in database users and roles, for example: dbo, guest, sys, and INFORMATION_SCHEMA.
The default schema for a newly created database is dbo, which is owned by the dbo user account. By default, when you create a new user with the CREATE USER command, the user will take dbo as its default schema name.
Syntax
The following lines illustrate simplified version of the CREATE SCHEMA statement:
CREATE SCHEMA schema_name
[AUTHORIZATION owner_name]
Ex.
CREATE SCHEMA product_services;
GO
Once you execute the ‘CREATE SCHEMA’ statement, you can find the recently created schema under the Security > Schemas of the database name.
You can use below query to list all schema in the current database.
SELECT
s.name AS schema_name,
u.name AS schema_owner
FROM
sys.schemas s
INNER JOIN sys.sysusers u ON u.uid = s.principal_id
ORDER BY
s.name;
You can see output in below image.
You can also read about ASP.NET, JQuery, JSON, C#.Net
I hope you get an idea about How to create schema in sql server.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you liked this post, don’t forget to share this.