数据库

  创建 删除 修改
模式 create schema drop schema  
create  table drop  table alter table
视图 create view   drop view  
索引 create index drop index  alter index

定义模式:create  schema 《模式名》 authorization 《用户名》表定义语句  视图定义语句  授权定义语句//未指定模式名默认为用户名

删除模式:drop  schema 《模式名》《cascade级联:删除模式的同时也把该模式中所有的数据库对象全部删除|restrict限制:me没有定义任何下属对象时才能执行drop》

定义表:create table《表名》(《列名》《数据类型》 约束条件,

              《列名》《数据类型》 约束条件,

                                                     表级约束条件)

create  table student 
(sno char(9) primary key  //主码
sname char(20) unique  //取唯一值
ssex char(2)
)
  cname char(40) not null //非空
foreign key (cpno)  references  course (cno)//cpno是外码参照表course cno
 
foreign key (sno )  reference  student(sno)  //sno是外码参照student 的sno
char (n) ,  character(n) 长度为n的定长字符串
varchar (n) charactervaring(n) 最大长度为n 的变长字符串
int 长整数(4字节)
smallint 短整数(2字节)
bigint 大整数(8字节)
float(n) 可选精度的浮点数,精度至少为n个字节
date 日期,包含年月日,格式YY-MM-DD
time 时间,包含时秒分,格式HH-MM-SS

修改表:

alter   table 《表名》
add column 《列名》《数据类型》 完整性约束
add 《表级完整性约束》
drop column 《列名》cascade |restrict
drop constraint <完整性约束名》restrict|cascade
alter column 《列名》《数据类型》

 

posted @ 2022-06-06 22:33  小白糖  阅读(36)  评论(0)    收藏  举报