欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

SQLServer的增删改查

程序员文章站 2023-04-06 13:36:49
T-SQL常用语句创建数据库: CREATE DATABASE [数据库名] CREATE DATABASE [School]删除数据库: DROP DATABASE [数据库名] DROP DATABASE [School]创建表: CREATE TABLE [表名]([列名] [类型](长度) ......

t-sql常用语句
创建数据库:
create database [数据库名]
create database [school]
删除数据库:
drop database [数据库名]
drop database [school]
创建表:
create table [表名]([列名] [类型](长度) 设置,列名 类型(长度) 设置)
create table [student] ( [name] [varchar](11) identity(1,1) , [id] [int](11) not null)

删除表:
drop table [表名]
drop table [mytest];
增加列:
alter table [表名] add 列名 设置
alter table [student] add commission money null

删除列:
alter table [表名] drop column [要删除列];
alter table [student] drop column [test];
添加行:
insert into [表名](列名) values (值);
insert into [grade](gradename) values ('h1');
删除行:
delete from [表名] where [gradeid]>=4;//条件
delete from [grade] where [gradeid]>=4;
更新行中数据:
update [表名] set [要修改列]=要修改值 where [gradeid]=8;//条件
update [grade] set [gradename]='test' where [gradeid]=8;
查询数据:

显示所有:
select *from 表名;
select *from grade;

显示部分:
select [列名],[列名] from [查询表];
select [studentno],[studentname] from [student];

显示含空值:
select *from [查询表] where [列]is null;//is null 是否 is not null不是空
select *from [student] where [studentname]is null;

限制显示行:
select top 3 *from [表名];//top 值:显示多少行
select top 3 *from [student];