创建/删除数据库
if object_id(N‘mytest‘) is not null drop DATABASE mytest; GO create DATABASE mytest ; go
查看数据库
use mytest; select name, size, size*1.0/128 AS [Size in MBs] from sys.master_files where name=‘mytest‘;
创建表
create table t_user(id int primary key, name varchar(100));
修改表结构
alter table t_user add state int;
注:此处不可以用表的别名。
插入数据
user mytest go declare @i int; set @i = 1; while @i < 100 begin insert into dbo.t_user (id,name) values(@i,‘name_‘ + convert(varchar(20),@i)); set @i = @i + 1; end;
插入数据可以单个记录插入,也可以批量插入。
操作表(增、删、改)
select * from t_user ; delete from t_user ; update t_user set state = 1 ;