数据库 模式 表 索引 的 创建 修改 删除

database schema table index create-alter-drop

1.数据库的创建与删除和使用

create database SQL; 
drop database SQL;
use SQL;  

2.模式\架构的创建和删除(属于用于guest)

--默认在架构dbo下 和用户dbo下
create schema TTY authorization guest;
drop schema TTY;

3.表的创建和删除(需要注意 只有表为unique才能被其他表当作外键)

create table Student(
	Sno char(9) primary key,
	Sname varchar(20) unique,
	Sex char(2),
	Sdept char(20)
);

4.修改表

--表 XX 添加 属性名 类型
alter table Student add Entrance date;
alter table Student add aha char(10);
alter table Student add zzc char(10) not null;
--表 XX 删除 列 列名(添加unique约束不能删除)
alter table Student drop column  aha;
--表 XX 修改 列 列名 类型(添加unique约束不能修改)
alter table Student alter column zzc  int;
--删除约束
alter table Student drop  constraint UQ__Student__1CC0725B1A14E395;

--常用完整性约束
--给属性添加约束
--主码约束 primary key
--唯一性约束 unique
--非空约束 not null
--参照完整性约束 foreign key references
alter table Student add unique(Entrance);
alter table Student add unique(Aha);

5.索引的创建与删除

create unique index Courno on Course(Cno);
drop index Course.Courno;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值