数据库_demo1
1.模式
-
权限:
获取数据库管理员权限的用户或者拥有管理员赋予的创建模式的权限的用户能创建模式
-
创建语法格式
modeName为模式名(不写默认为用户名), username指定该模式创建的对象
create schema "modeName" authorization username;
-
本质:
创建了一个命名空间
2.基本语法
-
数据库
- 创建
create database ss;
- 删除
drop database ss;
-
表
-
指定数据库
use ss;
-
创建
create table tb_demo1( name1 varchar(12), age1 int ); create table tb_demo2( name2 varchar(13), age2 int );
- 增加
-- 添加值 insert into tb_demo1(name,age) values('lihua', 12); -- 添加列 alter table tb_demo1 add column new_column varchar(12); -- 添加主键约束 alter table tb_demo1 add constraint name1 primary key tb_demo1(name1); alter table tb_demo1 add constraint name1 primary key tb_demo2(name2); -- 添加唯一性约束 -- 唯一约束:可以在一个字段,一组字段或一个表上定义唯一性约束,保证值不相同 alter table tb_demo1 add constraint name1 unique (name1); alter table tb_demo1 add constraint name1 unique tb_demo1(name1); alter table tb_demo1 add constraint name1 unique tb_demo2(name2); -- 添加检查约束(约束值的范围) alter table sss add constraint age check(age > 0 and age < 40);
-
删除
-- 删除表 drop table tb_demo1; -- 删除列 alter table tb_demo1
-