SQL基础
数据定义语言(DDL)
(mysql自增auto_increment)
CREATE
CREATE TABLE table_name
(
column_name1 data_type(size),
column_name2 data_type(size),
column_name3 data_type(size),
....
);
A:
create table A (id number(10) not null auto_increment unique,
name char(30),
status char(8),
primary key(id))
B:
create table B(id number(10) not null auto_increment unique,
name char(30),
aid number(10),
primary key(id),
foreign key(aid) references A(id)
)
Alert
添加字段:
ALTER TABLE table_name
ADD column_name datatype
删除字段:
ALTER TABLE table_name
DROP COLUMN column_name
修改字段:
ALTER TABLE table_name
ALTER COLUMN column_name datatype
DROP
drop table A
DML(数据操纵语言)
Insert
#insert into values
Insert into Table2(field1,field2,...) values (select value1,value2,... from Table1);
#insert into select
Insert into Table2 select * from Table1
或者
Insert into Table2(field1,field2,...) select value1,value2,... from Table1
Delete
delete from sc where .....
Update
update student set name='zhangsan'