SQL Server language create database, create table, modify table


We will complete the process from table creation to query in the form of statements

custom database


First we need to create a non-system database

define a database

create database <命名>

After creating the database, we need to jump the query statement to our self-built database before creating the table. We use the following code to complete this operation

use <命名>
go

Define base table

create a table

create table <命名>{
<列名><数据类型>[列级完整性约束],
<列名><数据类型>[列级完整性约束],
<列名><数据类型>[列级完整性约束],
primary key<列名>
};

The primary key defines the primary key and is placed in the last row of the created table
.

In addition to basic tables, you can also create table-to-table joins

Create a foreign key

foreign key<命名> references(被参照列)

When defining a foreign key, the referencing table and the referenced table can be the same table

Modify the base table

clause effect
ADD Add to
DROP delete
ALTER choose

delete table

drop table <命名>

Add and delete operations on table columns

ALTER table <命名>
add[column]<新增列名><数据类型>[完整性约束]
add <表级完整性约束>
drop[column] <列名>

special definition of list

cascade 和它相关联的所有对象一起删除,例如视图

Guess you like

Origin blog.csdn.net/qq_50767141/article/details/115465639