有关数据库操作的知识总结

来源:互联网 发布:nginx lua 连接redis 编辑:程序博客网 时间:2024/06/05 17:10
Oracle数据库创建过程
--建立表空间
create tablespace GRID_PART
logging datafile 'D:\oracle\oradata\part\GRID_PART.dbf' 路径是提前设置好的,存在的
size 50m autoextend on next 50m maxsize 20480m extent management local;

--建立临时表空间
create temporary tablespace GRID_PART_TEMP
tempfile 'D:\oracle\oradata\part\GRID_PART_TEMP.dbf'
size 50m autoextend on next 50m maxsize 5120m extent management local;

--建立用户
create user GRID_PART identified by mapapp
default tablespace GRID_PART
temporary tablespace GRID_PART_TEMP;

--用户授权
grant connect, resource, dba to GRID_PART;

--然后在这个用户下建立各表
创建数据库实例之后才可以创建用户,创建表空间,创建表。所以真正使用数据库是从创建实例之后开始的。

建表语句
create table 表明 (列名 类型,列名 类型 )
create table student
(sid int(10) primary key, //主键
sname char(12),
cid int(10),
foreign key(cid) references course //外键
);
insert into student (sid, sname) values (01, 'tom');
delete from student where sid=1;
update 表名 set 修改内容 where 条件
update student set name='mary' where sid=1;
select * from student where sid=1;
向表中添加列
alter table [表名] add column [字段名] datatype;
alter table student add sex char(12);
修改字段数据长度
alter table [表名] modify column [列名] 类型
alter table student modify sid int(20);
重命名一张表
rename table 源表名 to 新表名;
alert table 原表名 rename 新表名
alert table 原表名 rename to 新表名;
删除表
drop table 表名;
增加字段
alert table 表名 add column 列名 数据类型 约束;
alert table 表名 add 列名 数据类型 约束;
删除字段
alert table 表名 drop column 列名
alert table 表名 drop 列名;
重命名一列
alert table 表名 change 原列名 新列名 数据类型 约束;(数据类型不能省略,否则失败)
改变数据类型
alert table 表名 modify 列名 新数据类型;

0 0
原创粉丝点击