您的位置:首页 > 数据库

T-SQL 增删改查操作

2016-03-13 10:36 453 查看
T-SQL

1.创建表

create table Car
(
Code varchar(50) primary key ,
Name varchar(50) not null,
Time date ,
Price float ,
Brand varchar(50) references Brand(Code)
);

create table Brand
(
Code varchar(50) primary key ,
Name varchar(50)
);

create table PinPai
(
Ids int auto_increment primary key,
Name varchar(50)
);

primary key 主键

not null 非空

references 引用

auto_increment 自增长

注意:所有符号必须是英文状态下的

每个表创建完之后加分号

表里面的最后一列写完之后不要加逗号

删除表:
drop table PinPai

数据的操作:CRUD操作 增删改查

1.添加数据:

insert into Brand values('b001','宝马5');#第一种方式

insert into Brand (Code) values('b002');#第二种方式

insert into PinPai (Name) values('大众');#处理自增长列

insert into PinPai values('','大众');#处理自增长列

2.最简单查询

select * from PinPai #查询所有数据

select * from PinPai where Ids = 1;#根据条件查询

3.修改

update PinPai set Name ='保时捷' where Ids = 4; #修改某一条数据

update Car set Name = '哈弗' , Time = '2012-3-4' , Price = 16 , Brand = 'b002' where Code = 'c001'

4.删除数据

delete from Brand #删除所有数据

delete from PinPai where Ids = 4; #根据条件删除数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: