2016/3/13 MySQL additions and deletions to the CRUD with code implementation

Source: Internet
Author: User

Implementing database data entry with code
T-SQL statements
Query statement divided into several blocks
① Creating a Table
CREATE TABLE Car
(Code varchar () primary key, #primary key primary key to define primary key column
Name varchar (not NULL), #not null non-null
Time Date,
Price float,
Brand varchar references brand #references reference to create foreign keys to build foreign keys from tables
);

CREATE TABLE Brand (

Code varchar (primary key),
Ame varchar (50)
);

The error is due to the use of parentheses in the Chinese state. The correct parentheses are shown in red

② Self-growth table
CREATE TABLE Pinpai (
IDS int Auto_increment primary KEY, #auto_increment self-growth
Name varchar (50)
);

Note: All symbols must be in the English state,
After each table is created, add a semicolon; There is a conflict between multiple tables without semicolons.
Do not add a comma after the last column in the table is finished.

To delete a table:
drop table Pinpai

Database operation: CRUD additions and deletions

1, how to add data to the database
INSERT into Brand values (' b001 ', ' BMW X5 '); #第一种方式
INSERT into Brand values (' b002 '); #第二种方式
Insert into Pinpai (Name) VALUES (' VW '); #自增长时添加name add must have primary key value when not self-growing
INSERT into Pinpai values (' ', ' VW '); #处理自增长列

2, the simplest query
SELECT * FROM Pinpai #查询所有数据 * represents columns

SELECT * from Pinpai where Ids=1; #根据条件查询

3, modify the data
Update + table name set column name = "" Where primary key =value; #主键是不能修改的
Update Pinpai set name= ' Porsche ' where ids=3;
Update car set name= ' Harvard ', Time= ' 2012-3-4 ', price= ' + ', brand= ' b002 ' where code= ' c001 '
4. Delete data
Delete from Brand #删除表内所有数据
Delete from Brand where ids=4; A row of data #删除表内主键IDS to 4

2016/3/13 MySQL additions and deletions to the CRUD with code implementation

Related Article

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.