当前位置:网站首页>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
边栏推荐
- 多表查询之子查询_单行单列情况
- Curse of knowledge
- System a uses window.open to call system B, and system B carries data back to system a after processing the business
- Spark Learning: compile spark source code in win10
- 07 Jason module
- LiteOS_ a - SYS_ The run() function is missing a header file.
- The best time to buy and sell stocks includes handling charges (leetcode-714)
- Arduino drive Lora module node
- Reading makes people improve my list
- [STM32 learning] (12) STM32 realizes LCD1602 simple static reality
猜你喜欢
![[STM32 learning] (6) use of serial port 1 (usart1)](/img/b1/430d3501a99e46958c066f7fd7eee9.png)
[STM32 learning] (6) use of serial port 1 (usart1)

The heads of the five major international institutions called for urgent action to deal with the global food security crisis
![[STM32 learning] (15) STM32 realizes DHT11 temperature and humidity acquisition and display](/img/f2/6fcd4b2e747b4ceb52a52eda0c1af4.png)
[STM32 learning] (15) STM32 realizes DHT11 temperature and humidity acquisition and display

Spark Learning: Spark implementation of distcp
![[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)](/img/dd/d29a5be7306580ad388ba6487d230f.png)
[robot learning] mechanism kinematics analysis and MATLAB simulation (3D model +word report +matlab program)

Deployment and analysis of coredns

Friends come to interview a unicorn company in Beijing at leisure. The interview question is priced at 25K

What's the difference between testing / developing programmers' professionalism and salted fish? They don't want to be excellent coders?

【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)

Home raiding III (leetcode-337)
随机推荐
Arduino serial port information reading and output
Use of jstack "JVM common commands"
note: expected ‘void * (***)(void ***)’ but argument is of type ‘void (*)(void *)’
Embedded development: Tools - optimizing firmware using DRT
Looting (leetcode-198)
Lung CT segmentation challenge 2017 dataset download and description
[STM32 learning] (17) STM32 realizes LCD12864 display serial implementation
PHP log base - monolog knowledge collation
ASI-20220222-Implicit PendingIntent
[STM32 learning] (13) STM32 realizes ultrasonic ranging (hc-sr04)
Raspberry Pie:: no space left on device
Yarn: unable to load file
【机器人学习】机构运动学分析与matlab仿真(三维模型+word报告+matlab程序)
PHP debugging tool - socketlog installation and usage
[C language] implementation of three versions of address book small project (including source code)
[STM32 learning] (15) STM32 realizes DHT11 temperature and humidity acquisition and display
Tencent 5g innovation center was established, laying out key directions such as unmanned ports, smart mines and E-sports events
Reading makes people improve my list
[STM32 learning] (7) use of serial port 2 (usart2)
Wechat applet