SQL语句的基本操作

php中文网
发布: 2016-06-07 17:10:04
原创
1174人浏览过

--创建数据库create database Etp; --连接数据库connect to Etp; --断开连接disconnect Etp; --查看当前数据库下有哪些表list ta

--创建数据库
create database Etp;


--连接数据库
connect to Etp;


--断开连接
disconnect Etp;


--查看当前数据库下有哪些表
list tables;


--建表
create table studentInfo(
 stuno char(5) not null,
 stuname varchar(8),
 stubirth date
);


--查看表结构
describe table studentinfo;


--新增表字段
alter table studentinfo add stutel int;
alter table studentinfo add abc int;


--修改字段类型
alter table studentinfo alter column stutel set data type char(11);


--删除字段
alter table studentinfo drop column abc;


--增加一个非空约束
alter table studentinfo alter column stuname set not null;

 

Shoping购物网源码
Shoping购物网源码

该系统采用多层模式开发,这个网站主要展示女装的经营,更易于网站的扩展和后期的维护,同时也根据常用的SQL注入手段做出相应的防御以提高网站的安全性,本网站实现了购物车,产品订单管理,产品展示,等等,后台实现了动态权限的管理,客户管理,订单管理以及商品管理等等,前台页面设计精致,后台便于操作等。实现了无限子类的添加,实现了动态权限的管理,支持一下一个人做的辛苦

Shoping购物网源码 0
查看详情 Shoping购物网源码

--重构表
reorg table studentinfo;

 

--增加一个唯一约束
alter table studentinfo alter column stutel set not null;
alter table studentinfo add constraint un_stutel unique(stutel);

 

--添加检查约束
alter table studentinfo add column stuAge int;
alter table studentinfo add constraint ch_stuAge check(stuAge > 0 and stuAge

 

--添加主键约束
alter table studentinfo add constraint pk_stuno primary key(stuno);

 

--删除表
drop table studentinfo;

 

--创建表的同时添加约束方式1
create table studentinfo(
 stuNo int not null,
 stuName varchar(8) not null,
 stuAge int,
 stuTel char(8),
 constraint pk_stuNo primary key(stuNo),
 constraint un_stuName unique(stuName),
 constraint ch_stuAge check(stuAge >=0 and stuAge );

 

--创建表的同时添加约束方式2
create table studentinfo(
 stuNo int not null primary key,
 stuName varchar(8) not null unique,
 stuAge int check(stuAge >=0 and stuAge  stuTel char(8)
);

 

--添加主外键
--新增班级表
create table classInfo(
 classId int not null primary key,
 className varchar(20)
);

 


--建表的同时添加外键
create table studentinfo(
 stuNo int not null,
 stuName varchar(8) not null,
 stuBirth date not null,
 stuAge int,
 stuTel char(8),
 fclassId int,
 stuBirth date not null,
 constraint pk_stuNo primary key(stuNo),
 constraint un_stuName unique(stuName),
 constraint ch_stuAge check(stuAge >=0 and stuAge  constraint fk_fcalssId foreign key(fclassid) references classInfo(classId)
);


-- 自增
create table studentinfo(
 stuNo int not null generated always as identity(start with 1 ,increment by 1),
 stuName varchar(8) not null,
 stuAge int,
 stuTel char(8),
 fclassId int,
 stuBirth date not null,
 constraint pk_stuNo primary key(stuNo),
 constraint un_stuName unique(stuName),
 constraint ch_stuAge check(stuAge >=0 and stuAge  constraint fk_fcalssId foreign key(fclassid) references classInfo(classId)
);

linux

相关标签:
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号