当前位置:网站首页>Basic SQL operations
Basic SQL operations
2022-07-24 10:06:00 【xingxg.】
Catalog
form
create database test
-- Create student table Student
create table Student(Sno char(12) primary key,
Sname char(8) unique,
Age smallint,
Sex char(2))
-- Create a student course selection table Sc
create table Sc(Sno char(12),
Cno char(4),
Grade smallint,
Primary key(Sno,Cno))
-- Create a curriculum Course
create table Course(Cno char(6),
Cname char(20) not null,
Teacher char(8))
-- Delete table Course
drop table Course
-- stay SC In the table , Establish foreign code constraints ,
--Sno It's the outside code , The reference table is Student(sno);
alter table Sc
add foreign key(Sno) references Student(Sno)
-- Add column
alter table Student
add Sdept char(8) not null
-- Delete column
alter table Student
drop column Age
-- Modify the column
alter table Student
alter column Sex char(4) not null
-- Add constraints
alter table Student
add unique(Sex)
-- Delete constraints
alter table Student
drop constraint UQ__Student__CA1E3C800519C6AF
-- stay student Create about attributes on the table Sno Unique index of
create unique index Stusno on Student(Sno)
-- Insert data into table
insert
into Student
values ('1', ' Zhang Tian ', ' male ', ' Computer ')
-- see Student List the information
select * from Student
-- If in student In the table to delete ’202001020101’ This record
-- Delete column 、 surface use drop , Delete tuples ( Specific information ) use delete
delete
from Student
where Sno = '202001020101'
-- to Student Table to add “ Admission time ” Column , The data type is date
alter table Student
add S_entrance date
-- Change the data type of age from character type to integer type
alter table Student
alter column Sage int
-- Add constraints
-- Add the constraint that the student number must take a unique value
alter table Student
add unique(Sno)View :
Treat the view as a table .
-- Create a view , Count the number of courses selected by each student , The student number is required to be output 、 The number of elective courses -- See the table , Easy to insert data select * from Student select * from Sc; go -- View name List name create view Num_course(Sno,Num_course) as select Sno,COUNT(*) from Sc group by Sno go -- Before students take courses , There must be a course , This is the function of outer code !!! -- Insert courses and two students' elective schedules insert into Course values ('1','os',' Teacher wang '), ('2','cs',' Miss Liu ') -- 2 Student No insert into Sc values ('202001020102','1',80),('202001020102','2',90) -- 3 Student No insert into Sc values ('202001020103','1',95) -- View view select * from Num_course -- Create a student course selection view , The student number is required to be output 、 full name 、 Course name go create view Course_Student( Student number , full name , Course name ) as select Student.Sno,Sname,Cname from Student,Sc,Course where Student.Sno = Sc.Sno and Sc.Cno = Course.Cno go
边栏推荐
- Raspberry Pie: /bin/sh: 1: bison: not found
- Rust tokio:: task:: localset running mode
- Knapsack problem of dynamic programming -- three lectures on knapsack (01 knapsack, complete knapsack, multiple knapsack)
- Countdownlatch and join [concurrent programming]
- [STM32 learning] (16) STM32 realizes LCD1602 display (74HC595 drive) - 4-bit bus
- 二叉树、二叉树排序树的实现及遍历
- 2022, enterprise unified process platform design and integration specifications refer to thubierv0.1
- [STM32 learning] (4) press the key to control the flow light
- What's the difference between testing / developing programmers' professionalism and salted fish? They don't want to be excellent coders?
- Scala learning: why emphasize immutable objects?
猜你喜欢
![[C language] implementation of three versions of address book small project (including source code)](/img/3b/926001332ec05378de4c35dc28ed55.png)
[C language] implementation of three versions of address book small project (including source code)

Development history of the first commercial humanoid biped robot in China

缓冲区的概念真的理解么?带你揭开缓冲区的面纱~

Implementation principle of acid in MySQL

Spark Learning: a form of association in a distributed environment?

error: field ‘XXX’ declared as a function

Web page opening speed is very slow, how to solve it?

Spark Learning: using RDD API to implement inverted index

Compilation and linking of programs

Android Version Description security privacy 13
随机推荐
Spark Learning: using RDD API to implement inverted index
Installation UMI tutorial (error reporting and solutions)
cannot unpack non-iterable NoneType object
Use of jstack "JVM common commands"
Trie tree template 2
Looting (leetcode-198)
Countdownlatch and join [concurrent programming]
Spark Learning: build SQL to meet the specified optimization rules
Mysql8.0 authorized remote login
[STM32 learning] (8) stm32f1 general timer configuration
Can the "self-help master" who has survived the economic crisis twice continue to laugh this time?
It is reported that the prices of some Intel FPGA chip products have increased by up to 20%
二叉树、二叉树排序树的实现及遍历
[STM32 learning] (10) stm32f1 general timer realizes pulse counter
Excuse me, what are the financial products with an annual interest rate of 6%
The most complete solution for distributed transactions
An article takes you to understand the operation of C language files in simple terms
Ask you to build a small program server
PHP Basics - session control - cookies
At the moment of the epidemic, we need to work harder, aoligui