sql入门(5)------SQLServer5

sql入门(5)------SQLServer5
--注释

use master; --切换到系统数据库
go

if exists(select * from sysdatabases where name='mydb3')
drop database mydb3;
go

create database mydb3
on primary
(
name='mydb3_data',
fileName='e:\mydb3_data.mdf',
size=5mb,
maxsize=20mb,
filegrowth=2mb
)
log on
(
name='mydb3_log',
fileName='e:\mydb3_log.ldf',
size=3mb,
filegrowth=10%
)
go

use mydb3;--切换到创建好的数据库
go

if exists(select * from sysobjects where name='info')
drop table info;
go

--创建数据表
create table info
(
id int primary key identity(1,1),
name varchar(20),
age int
)
go
if exists(select * from sysobjects where name='info2')
drop table info2;
go

--创建数据表
create table info2
(
id int primary key,
name varchar(20),
age int
)
go
-----------------------------
--info2不是自动增长列
--添加数据
insert into 表名称(id,name,age) values(值1,'值2',值3);
--注意:如果字段的类型是字符的,在值的两边,要加上单引号

insert into info2(id,name,age) values(1,'成龙',22);

-------------
--info表,id为自动增长列

insert into info(name,age) values('张三',23);
insert into info(name,age) values('张1',24);
insert into info(name,age) values('张2',25);
insert into info(name,age) values('张4',26);
insert into info(name,age) values('张5',27);

--查询
select * from info;

select id,name,age from info;
select id from info;

select * from info where id=6;
select * from info where name='张三';

--修改
update info set age=35;
update info set age=200 where id=1;

update info set name='李四',age=88 where id=2;

-----------------
--删除
delete  from info;--删除数据表的所有数据

delete from info where id=13;

你可能感兴趣的:(sql)