用代码编辑数据库T-SQL语句
1、创建表
create table Car
(
Code varchar(50) primary key,
Name varchar(50),
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, //自增长列.自增的数据类型是int
Name varchar(50)
);
2.数据的操作:CRUD操作
(1)添加数据
insert into Car values('1','汽车','大众','2013-2-12','1100','白色'); //添加一整行数据
insert into Brand(Code) values('b001'); //添加某一单元的数据
insert into Brand values('','奇瑞'); //处理自增列
[删除数据后自增列从1开始: truncate table 表名]
(2)删除某个位置数据
delete from Car where Ids=3;
(3)修改数据
update PinPai set Name='大众' where Ids=4; //修改某一列数据
update PinPai set Name='汽车2',Brand='现代',Time='2013-2-30',Price='2289',Color='黄色'
where Code='2'; //修改一整行数据
(4)查询所有列
select*from PinPai
查询对应行,筛选条件
select*from PinPai where Ids=1; select*form PinPai where Code='3';