table of Contents
One, database operation statement
Second, the data table operation statement
Create a new table from another table
Three, data manipulation statements
Insertion of data in the data table
Modification of some data in the data table
Data table or deletion of elements in the table
Hello, hello, I am the little gray ape! A programmer who can write bugs!
Recently, I am learning about SQL server database, so I have summarized some common operation statements of the database. Share it with friends here. Start with the most basic database operation statement.
One, database operation statement
Create database operation
create database 数据库名
/*新建数据文件*/
on(
name = 数据文件逻辑名称,
filename = '数据文件物理名称.mdf',
size = 文件起始大小,
maxsize = 文件最大大小,(不设置时默认无限大)
filegrowth = 文件每次增长大小(以MB或百分比增长)
)
/*创建日志文件*/
log on(
name = 日志文件逻辑名,
filename = '日志文件物理名.ldf',
size = 日志文件初始大小,
maxsize = 文件最大大小,(不设置时默认无限大)
filegrowth = 文件每次增长大小(以MB或百分比增长)
)
Modify the database
New data file
alter database 数据库名称
add file(
name=数据文件逻辑名,
filename='物理文件名.mdf',
size=数据文件初始大小,
maxsize=数据文件最大值,
filegrowth = 文件每次增长大小(以MB或百分比增长)
)
New log file
The difference between the newly added log file and the data file is that log must be added after add and the physical file name suffix is ldf
alter database 数据库名称
add log file(
name = 日志文件逻辑名,
filename = '物理文件名.ldf',
size = 日志文件起始大小,
maxsize=数据文件最大值,
filegrowth = 文件每次增长大小(以MB或百分比增长)
)
Use database
use database databaseName
Delete database
drop database databaseName
Second, the data table operation statement
New data table
use 数据库名
create table 表名{
liet1 数据类型1,
liet2 数据类型2,
liet3 数据类型3
}
Create a new table from another table
use databaseName
select list1,list2,list3 into newTableName
from tableName
New column in data table
use databaseName
alter table tableName
add列名 数据类型
Three, data manipulation statements
Insertion of data in the data table
/*多行插入时括号后加逗号*/
use databaseName
insert into tableName values ('info1','info2'...)
Modification of some data in the data table
use databaseName
update tableName
set 修改列1=修改的内容1,修改列2=修改的内容2
where 先决条件
Data table or deletion of elements in the table
use databaseName
delete tableName
where 先决条件
Well, some common operations on database creation and data tables will be shared here with friends. If there are deficiencies, I hope you can make corrections. Later, we will continue to update the summary of related operation statements such as database queries. .
Feel good, remember to like and follow !
The big bad wolf will accompany you to make progress together!