1. 程式人生 > 其它 >Linux命令列與shell指令碼程式設計大全(一)

Linux命令列與shell指令碼程式設計大全(一)

create database MySQlCrashCourse;

use MySQlCrashCourse;

create table Student(
 Sno char(9)  primary key ,
 Sname char(20) unique ,
 Ssex char(2),
 Sage smallint,
 Sdept char(20)
);
create table Course(
    Cno char(4)primary key ,
    Cname char(40) not null ,
    Cpno char(4),
    Ccredit smallint,
    foreign key (Cpno)references Course(Cno)
);
create table SC(
    Sno char(9),
    Cno char(4),
    Grade smallint,
    primary key (Sno,Cno),
    foreign key (Sno)references Student(Sno),
    foreign key (Cno)references Course(Cno)
);

insert into Course(Cno,Cname)value (1,'資料庫')
    ,(2,'數學')
    ,(3,'資訊系統')
    ,(4,'作業系統')
    ,(5,'資料結構')
    ,(6,'資料處理')
    ,(8,'PASCAL語言');
show databases;

select *from Student;

## 查詢時間
select now();

## 查詢當前使用者
select user();

##建立索引 alter table 表名 add index 索引名(索引值)
alter table Student add index ind_id(Sno);

##刪除索引
drop index ind_id on Student;

## 模糊查詢
select * from Student where Sno  like 1;

select * from Student where  Sno not like 1;

## %替代多個字元 _替代單個字元
select * from Student where Sname  like '_a%';

## 查詢多個值
select *from Student where Sno in(201215121,201215122);

##別名
select Sno,concat(Sname,',',Ssex,',',Sdept)as site_info from Student;

## 內連線
select  Student.*,SC.* from Student inner join SC on Student.Sno = SC.Sno;

## 左連線
select  Student.*,SC.* from Student left join SC on Student.Sno = SC.Sno;

## 右連線
select  Student.*,SC.* from Student right join SC on Student.Sno = SC.Sno;

##完全連線
select  Student.*,SC.* from Student full join SC on Student.Sno = SC.Sno;