流云追风 2020-06-18
INSERT INTO table_name
(columnl, column2,)
VALUES(valuel, value2…)
SQL> desc userinfo
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
ID NUMBER(6) Y
USERNAME VARCHAR2(20) Y
USERPWD VARCHAR2(20) Y
EMAIL VARCHAR2(30) Y
REGDATE DATE Y
SQL> insert into userinfo values(1,‘lewen‘,‘123‘,‘‘,sysdate);
1 row inserted
SQL> select * from userinfo;
ID USERNAME USERPWD EMAIL REGDATE
------- -------------------- -------------------- ------------------------------ -----------
1 lewen 123 2020/6/17 2
SQL> insert into userinfo(id,username,userpwd) values(2,‘fadewalk‘,123);
1 row inserted
SQL> select username,userpwd from userinfo;
USERNAME USERPWD
-------------------- --------------------
lewen 123
fadewalk 123
SQL> create table userinfo1(id number(6,0),regdate date default sysdate);
Table created
SQL> select username,userpwd from userinfo;
USERNAME USERPWD
-------------------- --------------------
lewen 123
fadewalk 123
SQL> create table userinfo1(id number(6,0),regdate date default sysdate);
Table created
SQL> insert into userinfo1(id) values(1);
1 row inserted
SQL> select * from userinfo1;
ID REGDATE
------- -----------
1 2020/6/17 2
SQL> alter table userinfo modify email default ‘NULL‘;
Table altered
SQL> insert into userinfo(id) values(3);
1 row inserted
SQL> select id,email from userinfo;
ID EMAIL
------- ------------------------------
1
2
3 NULL
SQL> insert into userinfo(id,email) values(4,‘‘);
1 row inserted
SQL> select id,email from userinfo;
ID EMAIL
------- ------------------------------
1
2
3 NULL
4
CREATE TABLE table_new
AS
SELECT column1,....| *FROM table_old
SQL> select id,email from userinfo;
ID EMAIL
------- ------------------------------
1
2
3 NULL
4
SQL> create table userinfo_new as select * from userinfo;
Table created
SQL> desc userinfo_new
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
ID NUMBER(6) Y
USERNAME VARCHAR2(20) Y
USERPWD VARCHAR2(20) Y
EMAIL VARCHAR2(30) Y
REGDATE DATE Y
SQL> create table userinfo_new_1 as select id,username from userinfo;
Table created
SQL> select * from userinfo_new_1;
ID USERNAME
------- --------------------
1 lewen
2 fadewalk
3
4
INSERT INTO table_new
[(column1,.....)
SELECT columnl,....| *FROM table_old
SQL> insert into userinfo_new select * from userinfo;
4 rows inserted
SQL> select id from userinfo_new;
ID
-------
1
2
3
4
1
2
3
4
8 rows selected
SQL> insert into userinfo_new(id,username) select id,username from userinfo;
4 rows inserted
SQL> select id,username from userinfo_new;
ID USERNAME
------- --------------------
1 lewen
2 fadewalk
3
4
1 lewen
2 fadewalk
3
4
1 lewen
2 fadewalk
3
4
12 rows selected
UPDATE table_name
SET columnl=value1,.....
[WHERE conditions]
SQL> desc userinfo
Name Type Nullable Default Comments
-------- ------------ -------- ------- --------
ID NUMBER(6) Y
USERNAME VARCHAR2(20) Y
USERPWD VARCHAR2(20) Y
EMAIL VARCHAR2(30) Y ‘NULL‘
REGDATE DATE Y
SQL> update userinfo set userpwd=‘1234‘;
4 rows updated
SQL> update userinfo set userpwd=‘1111‘,email=‘‘;
4 rows updated
SQL> select userpwd,email from userinfo;
USERPWD EMAIL
-------------------- ------------------------------
1111
1111
1111
1111
SQL> update userinfo set userpwd=‘123456‘ where username=‘lewen‘;
1 row updated
SQL> select userpwd,email from userinfo;
USERPWD EMAIL
-------------------- ------------------------------
123456
1111
1111
1111
DELETE FROM table_name
[WTHERE conditions]
SQL> create table testdel as select * from userinfo;
Table created
SQL> delete from testdel;
4 rows deleted
SQL> delete from userinfo where username=‘fadewalk‘;
1 row deleted