SQL statement combat exercise

1 Create a database, delete the database

Note: The keyword does not have to be capitalized.

CREATE DATABASE sql_test
DROP DATABASE sql_test

2 New Table

TABLE `emp` the CREATE ( 
	` c_id` the INT (. 11) the AUTO_INCREMENT the COMMENT the NOT NULL 'ID', 
	`c_no` VARCHAR (. 8) the COMMENT the NOT NULL 'User ID' the COLLATE 'utf8_bin', 
	` c_name` VARCHAR (. 8) the NOT NULL the COMMENT 'name' COLLATE 'utf8_bin', 
	`c_sex` INT (11) the NOT NULL the DEFAULT '0' the COMMENT 'sex', 
	` c_phone_number` VARCHAR (23) NULL the DEFAULT NULL the COMMENT 'phone number' COLLATE 'utf8_bin', 
	`VARCHAR c_password` (64) NOT NULL COMMENT 'password' COLLATE 'utf8_bin', 
	`c_mail` VARCHAR (30) NULL the DEFAULT NULL the COMMENT 'Mail' COLLATE 'utf8_bin', 
	` c_address` VARCHAR (20) NULL the DEFAULT NULL the COMMENT 'home address' COLLATE' utf8_bin ', 
	`c_enter_date` the DEFAULT NULL NULL dATE the COMMENT' company entrance date ',
	`c_exit_date` DATE NULL DEFAULT NULL COMMENT 'termination date',
	`c_hidden_flag` INT (11) NOT NULL DEFAULT '0' COMMENT '(0) Normal (1) hidden', 
	a PRIMARY KEY (` c_id`), 
	the INDEX c_no`` ( `c_no`) 
) 
the COMMENT = 'user table' 
the COLLATE = 'utf8_bin' 
ENGINE = the InnoDB 
the AUTO_INCREMENT = 1 
;

ENGINE=InnoDB

InnoDB storage engine is a type of mysql database.

It provides transaction control function to ensure the successful implementation of a set of commands all.

When any command error occurs, the result of all commands are rolled back.

Constraints Constraint:

  • primary key
  • foreign key
  • unique
  • not null
  • default 
  • check  

[Main] key deletion / modification:

ALTER TABLE emp DROP PRIMARY KEY

ALTER TABLE emp ADD PRIMARY KEY (c_id)

[Column] additions and deletions:

ALTER TABLE emp ADD COLUMN c_test VARCHAR(20)

ALTER TABLE emp CHANGE COLUMN 'c_test' 'c_test_new' INT(10) DEFAULT 2 'utf8_bin' AFTER `c_hidden_flag`

ALTER TABLE emp DROP COLUMN c_test

Insert data:

INSERT INTO emp (c_id,c_no,c_name,c_password) VALUES (1,"JS963","ZFY","123")

update data:

UPDATE emp SET c_name="Zfy" WHERE c_id=1

delete data:

DELETE FROM `emp` WHERE  `c_id`=1

Sort by:

desc: descending; asc: Increment

SELECT * FROM `eps` ORDER BY `c_no` DESC, `c_name` ASC

Guess you like

Origin www.cnblogs.com/jszfy/p/11327708.html