DB2 simple command: Build table, increase and revise check

Source: Internet
Author: User
Tags db2 one table

DB2 Build Table:

Create table Tab_name (
   field 1   type not   null/default value

)

Change the type or length of a field in a table:

Alter TABLE Tab_name
     alter COLUMN todolist SET DATA TYPE <DATATYPE>

simple to delete and change:

Add an article:

INSERT into Tab_name (C1,C2,C3) VALUES (",", ",")

Add multiple lines:
INSERT into Tab_name (C1,C2,C3) VALUES (', ', ', ', '), (', ', ', ', '), (' ', ' ', ', '), (', ', ', '); comma separated

Insert data from one table into another table:

Insert into TAB1 (C1,C2) 
select c1,c2 from TAB2
such as:
INSERT INTO TEACHER (id,name,age)
Select Id,name, Age from STUDENT;

Modify Update:

UPDATE Table name 
    SET field name = ' character value ', field name = value, ...
    WHERE  Condition 

Remove Delete

DELETE from table name

WHERE condition ...

Note: If there is no where condition, the data in the entire table will be deleted.

Delete Table by: Droptable tabname;

Find:

Select column from table where condition
can not add where 

Conditional expression:

This figure is from the Internet

query removes duplicate rows: keyword distinct

SELECT DISTINCT field name 1, field name 2 from table name

To find data from multiple tables:

SELECT Field name 1, field Name 2 ... from table 1, table 2

WHERE table 1. field 1= table 2. Field 2

When the field name repeats, you can alias the table and then alias the field name.

Sub-query:

SELECT Field name 1, field Name 2 ... from table 1

where field 1= (SELECT field name from table name WHERE condition)



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.