当前位置:网站首页>Summary of basic knowledge of Oracle database SQL statements I: Data Definition Language (DDL)
Summary of basic knowledge of Oracle database SQL statements I: Data Definition Language (DDL)
2022-06-22 08:06:00 【EA development - green shirt code customer】
ORACLE database SQL Basics
1、 Create user
CREATE USER jack -- Create user
INDENTIFIED BY 123456 -- Set the password
ACCOUNT UNLOCK -- User unlock
2、 Authorize roles
GRANT CONNENT, -- Connect to the server session permissions
RESOURCE, -- Create table 、 stored procedure 、 trigger 、 Index and other permissions
DBA -- System permissions , Have permission to create users
TO jack
3、 Recycling permissions
REVOKE CONNENT FROM jack
4、 Modify the user
ALTER USER jack IDENTIFIED BY 654321
ALTER USER jack LOCK|UNLOCK
Data definition language (DDL)
CREATE command 、ALTER command 、DROP command
Create a student list
CREATE TABLE student_1(
sno varchar2(10),
sname varchar2(20),
sage number(3),
sbirthday date
)
Replicated table structure
CREATE TABLE student_2 AS
SELECT * FROM student_1 WHERE 1=2;
Copy table
CREATE TABLE student_3 AS
SELECT * FROM student_1;
Create result set table
CREATE TABLE student_2 AS
SELECT * FROM student_1 WHERE sage<=20;
Delete table
DROP TABLE student_1; -- You can roll back
TRUNCATE TABLE student_2; -- Cannot roll back
DELETE FROM student_3 WHERE 1=1; -- Delete data conditionally
Add columns
ALTER TABLE student_1 ADD ssex varchar2(2);
Change data type
ALTER TABLE student_1 MODIFY sno number;
Change column names
ALTER TABLE student_1 RENAME COLUMN sno TO id;
Delete column
ALTER TABLE student_1 DROP COLUMN ssex;
Modify the name of the table
ALTER TABLE student_1 RENAME TO student_0;
Add table comments
COMMENT ON TABLE student_0 IS ' Student list ';
Add table field comments
COMMENT ON COLUMN student_0.id IS ' Student ID';
See table notes
SELECT * FROM user_tab_comments
WHERE TABLE_NAME='student_0';
View table field comments
SELECT * FROM user_col_comments
WHERE TABLE_NAME='student_0';
Table constraints
1、PRIMARY KEY: Primary key constraint
2、FOREIGN KEY: Foreign key constraints
3、CHECK : Check constraint
4、UNIQUE : Unique constraint
5、NOT NULL: Non empty constraint
Create constraints
ALTER TABLE Table name ADD CONSTRAINT Constraint name Constraint content
Add primary key
ALTER TABLE student_0 ADD CONSTRAINT myconstraint PRIMARY KEY(id)
Add a foreign key constraint
ALTER TABLE student_0 ADD CONSTRAINT myforeingkey FOREIGN KEY (cno) REFERENCES course (cno)
add to check constraint
ALTER TABLE student_0 ADD CONStRAINT mycheck CHECK (ssex=' male ' or ssex=' Woman ')
Add unique constraints
ALTER TABLE student_2 ADD CONSTRAINT myunique UNIQUE(id)
Add non empty constraints
ALTER TABLE student_2 ADD CONSTRAINT mynotnull NOT NULL(id)
Delete constraints
ALTER TABLE student_2 DROP CONSTRAINT myunique
Create session level temporary tables
CREATE GLOBAL TEMPORARY TABLE table_name(col1,col2...)ON COMMIT PRESERVE ROWS;
Create transaction level temporary tables
CREATE GLOBOLTEMPORARY TABLE table_name(col1,col2...)ON COMMIT DETELE ROWS;
The role of temporary tables : Break down complex logic , Use temporary tables to store intermediate results , To facilitate the following logical processing . Some temporary data may need to be stored during program execution , These data need to be used during the whole program session, and so on .
Session level temporary tables are truncated only when the session ends , And the transaction level temporary tables do not matter COMMIT、ROLLBACK、 Or the session ends , The data in the temporary table will be truncated and emptied (TRUNCATE TABLE)
边栏推荐
- Template code overview
- Website sharing of program ape -- continuous update
- IP address planning
- Layer drawing method
- 模电实验——实验一 晶体管共射极单管放大器
- Mt4/mql4 getting started to mastering EA tutorial lesson 3 - common functions of MQL language (III) - common functions of K-line value taking
- 矩阵运算
- The significance of code coverage testing to programming white and its application
- Node red sends wechat official account message (template message)
- Seven challenges faced by CIO in 2022 and Solutions
猜你喜欢

多点闹钟实例
![[songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine](/img/47/62ad1e661e015438c40574f533d8f1.png)
[songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine

Stored procedures and functions of MySQL

(7) Bidirectional linked list

Template code overview

【Oracle 数据库】奶妈式教程 day11 数值函数

QT custom composite control (class promotion function)

Concatenate the specified character at the end of a number in a string

OSI and tcp/ip

【宋红康 MySQL数据库 】【高级篇】【06】MySQL的逻辑架构
随机推荐
Difference between ID instancetype nsobject *
Chmod Chmod command
Mt4/mql4 getting started to be proficient in EA tutorial lesson 6 - common functions of MQL language (VI) - common order function
Permission Operation of MySQL
Docker install redis
It operation and maintenance knowledge map
[songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine
QT combox的使用示例
MySQL query group by 1055 is the simplest and most convenient way to solve the problem perfectly
0基础自学stm32(野火)——什么是寄存器?
Skills required for O & M automation?
Restrict input type (multiple methods)
QT 自定义组合控件(类提升功能)
Kubernetes practice
How Navicat queries the password information of the connected database
MySQL backup - mysqldump
Idea reports an error "insufficient memory"
(9) Sequential queue and stack queue
C语言实现往MySQL插入和读取图片
Orientdb batch execute SQL