SQL表的简单操做

建立数据库表,进行增删改查是咱们操做数据库的最基础的操做,很简单,熟悉的请关闭,省得让费时间。sql

一、建立表:数据库

sql中建立数值类型字段要根据该字段值的增加状况选择类型:ide

tinyint 占1个字节,长度为 0-255spa

smallint 占2个字节,长度为 2^15 (-32,768) 到 2^15-1 (32,767)code

int 占4个字节,长度为 -2^31 (-2,147,483,648) 到 2^31-1 (2,147,483,647)blog

bigint 占8个字节,长度为 -2^63 (-9,223,372,036,854,775,808) 到 2^63-1 (9,223,372,036,854,775,807)it

Create Table Student(
Id tinyint primary key identity(1,1),
Name nvarchar(20),
Age int
)

二、用SQL为表添加一列table

Alter table Student 
add Class nvarchar(20)
go

三、修改SQL现有列的类型,好比从nvarchar改为varcharclass

Alter table Student
Alter column Name char(20)
go

四、用sql语句删除一列基础

Alter table student
Drop column class
go

五、SQL Insert 

Insert into Student(Name,Age) values('张三',18)
Insert into Student(Name,Age) values('李四',17)
Insert into Student(Name,Age) values('王五',17)

 六、Sql 更新一条数据

Update Student set Age=19 where Id=1

 七、删除一条数据

 
  
 
 

  

八、清空数据表:

truncate table Student

 

九、删除数据表

drop table Student

 

这些都是最基础最基础的操做,一个表的建立,增删改查,清空,删除数据,删除表。

但愿对看到你有些帮助。

欢迎拍砖!

相关文章
相关标签/搜索