我为大家整理了一些常用的SQL语句,如下:
一、数据库常用对象管理
1.创建模式
create schema 模式名;
2.切换模式
set schema 模式名;
3.删除模式
drop schema 模式名;
4.创建表空间
create table 表名(列名 数据类型 约束);
例如,创建一个名为 "employees" 的表,包含 id、name 和 age 三个列,可以使用如下的SQL语句:
create table employees (
id int primary key,
name varchar(50),
age int);
4.1增加列
alter table 表名 add column(列名 数据类型);
例如,如果我们有一个名为students的表,包含了id和name两个列,现在要向该表中添加一个新的列age,可以使用以下SQL语句:
alter table students
add age int;
4.2删除列
alter table 表名 drop column 列名;
例如,如果要从students表中删除之前添加的列age,可以使用以下SQL语句:
alter table students
drop column age;
4.3增加约束
alter table 表名 add constraint 约束名 约束类型;
例如,如果你想要在名为students的表上添加一个唯一约束,确保student_id列中的值是唯一的,你可以使用以下语句:
alter table students add
constraint unique_student_id unique (student_id);
4.4删除约束
alter table 表名 drop constraint 约束名;