3. Learn the command line management code

Source: Internet
Author: User

3. Learn the command line management code
The Great sailing age 1: Creation of the world

--------------table Operation: The World of Thieves king
CREATE DATABASE One_Piece
DROP DATABASE One_Piece


CREATE TABLE ROLE (
ID INT IDENTITY (+),
NAME VARCHAR (20),
Age INT,
Reward INT
)

CREATE TABLE Area (
ID INT IDENTITY (+),
NAME VARCHAR (20),
REMARK TEXT,
)
Sp_rename ' AREA1 ', ' area '
DROP TABLE Area


INSERT into ROLE (NAME, age, reward) VALUES (' Lu.fei ', 20, 5);
SELECT * from ROLE;
Delete from ROLE;

ALTER TABLE ROLE DROP COLUMN area_id;
ALTER TABLE ROLE ADD area_id INT;
ALTER TABLE ROLE MODIFY area_id BIGINT;

-----------2.SQL Constraint
/*
1.NOT NULL
2.UNIQUE
3.PRIMARY KEY: UNIQUE constraint with auto-defined
4.FOREIGN key: In one table FOREIGN key points to PRIMARY key in another table. The
5.CHECK CHECK constraint is used to limit the range of values in a column.
6.DEFAULT Default constraints are used to insert defaults into columns
*/
1.ALTER TABLE role MODIFY NAME not NULL
2.ALTER TABLE role ADD UNIQUE (NAME )
ALTER TABLE role ADD CONSTRAINT Uc_person UNIQUE (NAME, age)
ALTER table role DROP CONSTRAINT Uc_person
3.A Lter table role Add PRIMARY key (ID)
Alter TABLE role add CONSTRAINT Pk_person PRIMARY KEY (ID, NAME)
Alter TAB LE role DROP CONSTRAINT pk_person

4.ALTER TABLE ROLE ADD FOREIGN KEY (area_id) REFERENCES area (ID)
ALTER tabl E ROLE ADD CONSTRAINT fk_perorders FOREIGN KEY (area_id) REFERENCES area (ID)
ALTER TABLE ROLE DROP CONSTRAINT fk_peror DERs

5.ALTER TABLE ROLE ADD CHECK (age<30)
ALTER TABLE ROLE ADD CONSTRAINT chk_person CHECK (age<30 and NAME is not NULL)
ALTER TABLE ROLE DROP CONSTRAINT Chk_person
INSERT into ROLE (age, NAME) VALUES (5, ' Yai si ')

--6
Alter TABLE ROLE ALTER COLUMN reward SET DEFAULT ' not find '
Alter TABLE ROLE ALTER COLUMN reward DROP DEFAULT
------------3. Index

3. Learn the command line management code

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.