基本概念
库直接创建
库中的一级对象:模式,即全名空间,用这个命名存储空间来存放该库中的表、视图和索引对象。
创建模式的三种方式
【1】create schema sName authorization uName --为用户定义模式
【2】create schema authorization uName --以用户名方式命名模式名
【3】create schema sName authorization uName [create table…] --定义模式同时,在该模式下定义表等对象
具体示例
–create database testdb;
use testdb;
– 对于sqlserver2016,
– 模式,表,视图,索引,除表可以修改,其它对象都只能创建和删除
– create/drop
– table:create,alter,drop
– 模式是库的命名空间
– 给用户定义模式
create schema test authorization testdb;
–直接给全名空间
create table test.tab1(
col1 int
,col2 char(20)
,col3 numeric(7,3)
,col4 decimal(6,2)
,col5 datetime
);
– 给用户定义模式,同时在模式下定义表
create schema test01 authorization testdb
create table tab1(
col1 int
,col2 char(20)
,col3 numeric(7,3)
,col4 decimal(6,2)
,col5 datetime
);
–使用默认全名空间,即dbo
create table tab1(
col1 int
,col2 char(20)
,col3 numeric(7,3)
,col4 decimal(6,2)
,col5 datetime
);