A-A+

SQL基本语法(一)基础

2016年01月12日 sql 暂无评论 阅读 2,068 views 次

基础

 

select * from table_name;

select id from table_name

 

创建数据库表

CREATE TABLE table_name(

column_1 data_type,

column_2 data_type,

column_3 data_type,

);

 

eg:

CREATE TABLE celebs1 (id INTEGER,name TEXT,age INTEGER);

 

添加一条记录

INSERT INTO table_name(id,name,age) VALUES(1,'dupeng',29);

 

修改一条记录

UPDATE table_name SET age = 22 where id = 1;

update celebs set twitter_handle='@taylorswift13' where id=4;

 

添加一个字段

ALTER TABLE table_name ADD COLUMN phone_number text;

 

删除

delete from celebs where twitter_handle is null;

 

 

总结:

CREATE TABLE creates a new table.

INSERT INTO adds a new row to a table.

SELECT queries data from a table.

UPDATE edits a row in a table.

ALTER TABLE changes an existing table.

DELETE FROM deletes rows from a table.

标签:

给我留言