数据库增删改

use 数据库名
show tables 调用表格
select * from 表格名 调用所有内容
insert into 表格名 (列名) values (值) 增
update 表格名 set 列名=‘值’ where id=值 改
ALTER TABLE 表名 DROP COLUMN 列名; 删除列
alter table 表名 add 列名 属性 添加列
:drop table 表名 删除表

1.增加
insert into 表名 values(列的值,列的值)
2.删除
delete from 表名
3.修改
update 表名 set 列名=值
update 表名 set 列名=值 where 条件

T-SQL语句

1.创建数据库
create database test3;

2.删除数据库
drop database test3;

3.创建表
create table test
(
code varchar(20),
name varchar(20)
);

create table test1
(
code varchar(20) primary key,
name varchar(20)
);

create table test2
(
code varchar(20) primary key,
name varchar(20) not null
);

create table zhu
(
code int primary key,
name varchar(20)
);
create table cong
(
code int primary key,
name varchar(20),
zhu int,
foreign key (zhu) references zhu(code)
);

create table haoyou
(
ids int auto_increment primary key,
me varchar(20),
friends varchar(20)
);

4.删除表
drop table haoyou;


关键字:
primary key 主键
not null 非空
foreign key (列名) references 主表名(列名) 外键
auto_increment 自增长列

注意:1.每条语句后加分号
2.最后一列后面不加逗号
3.符号一定是英文的

自增长列 我的用户名 好友的用户名
1.联合主键
2.加一列自增长

作业:
1 . 修改表的语句

二:对数据的增删改查
CRUD操作
C:create 添加
R:read 查询
U:update 修改
D:delete 删除

1.C:添加数据
insert into 表名 values('n001','张三');

insert into test2 values('n001','');
insert into test2(code) values('n001'); 指定列添加
insert into haoyou values('zs','ls');

注意:
1.如果添加的数据是字符串,需要加<单引号>,如果是其他类型不要加单引号2.在添加数据的时候,值的数量要和列匹配
3.在添加数据的时候,可以指定列添加
4.如果要添加的列是自增长列,可以给一个空字符串

5.注释语法:#

原文地址:https://www.cnblogs.com/l123789/p/6122207.html