SqlServer 使用的常用命令


创建数据库

create database database_name

例如:create database test

创建表时先执行命令

use test

创建表

create table 表名(列名1 数据类型,列名2 数据类型 ,...)

例如:create table book(name char(20),writer varchar(20))

创建表时可以设置某些字段为自增型,但是字段属性必须是int型

create table 表名(列名 int identity(a,b))a 代表自增从 a 开始,

每次增加 b 个值(注意 a 和 b 必须都为int型,而且不能设置字段长度)

例如:create table book (book_id int identity(1,1))

表中插入数据

insert into 表名 values (字段一值,字段二值,...)

例如: insert into book values('狼图腾','姜戎')

注意varchar型和char型的字段值插入用英文单引号

修改表中列的数据类型

alter table 表名 alter column 列名 新的数据类型

例如: alter table book alter column varchar(20)

删除表中的所有字段值

delete 表名

例如: delete book

删除表

drop 表名

例如 :drop book

查看表的详细信息

sp_help 表名

例如: sp_help book

将表1 中的所有数据复制到表2 中:

insert into table1 select * from table2

原文地址:https://www.cnblogs.com/siriu-s/p/4130142.html