当前位置:网站首页>Creation and modification of basic tables and data in them by SQL statements of SQL Server
Creation and modification of basic tables and data in them by SQL statements of SQL Server
2022-07-26 11:30:00 【Baby paper d】
SQL Statement to create a basic table
create table { < Table name > | Database name . [ dbo . ] Table name }
(
Name data type [ Column level integrity constraints ]
[ , Name data type [ Column level integrity constraints ] ]
......
[ Table level integrity constraints ]
)
【 Column level constraints 】 It refers to adding primary key ( Primary key constraint )、unique( Uniqueness constraint ) or NULL、NOT NULL or identity(seed,increment)( Identity column )、default expression ( Specify default ).
【 Table level constraints 】 It means adding primary key ( Name , Name . . . ) ( Specify multiple columns as primary keys )、foreign key( Foreign key column name ) references Main table ( Name ) ( Create foreign key constraints ).
Another is to create a temporary table :
create table # Table name
. . . . . .
“#” Represents a temporary local table , Use in the current database , Delete when the current database is closed ;“##” Represents a global temporary table , It can be used in all databases , After closing all databases, delete .
SQL Statement to modify the basic table
Alter Table < Table name >
[ Alter column < Old column names >
New column names | New data types | [NULL | NOT NULL]
]
[ Add [column] < New column names > < data type > [ Integrity constraints ] ] -- Add column
[ Add < Table level integrity constraints > ] [ , . . . n ]
[ Drop [column] < Name > [cascade | restrict] ] -- Delete a column , If added cascade It means that other columns that reference this column will also be deleted , If added restrict, If the column is referenced by other objects , This column will not be deleted .
[ Drop constraint < Integrity constraint name ( Name )> ] -- Delete the integrity constraint of a column
Delete base table
Drop Table < Table name > [ cascade | restrict ] -- If added cascade When deleting the basic table, the related dependent objects will also be deleted , If added restrict, If there are objects that depend on this table , This table will not be deleted .
Maintenance of data in the table
insert data
insert < Table name >
[ ( Name , Name ,. . . ) ]
values (' data ',' data ',. . .) [ , ( ' data ', . . . ) ]
Column names and data are one-to-one correspondence , If no column name is specified , Sort by default column name
Modifying data
update Table name
set
Name = The new value [ , . . . n] -- This column will be changed to the new value
[ from Other table names [, . . .n] ] -- Specify that the data to be updated will come from other tables
[ where Conditions ] -- Restrict the rows to be updated by constraints , Instead of updating every row of data
Truncate Table Table name -- All rows in the table will be deleted , And the deletion of each line will not be included in the log file , In this way, the speed will be faster , in addition , The structure of the table 、 Column 、 constraint 、 Index and so on remain unchanged
边栏推荐
猜你喜欢

Cmake常用命令总结

easyui04

Getting started step by step using g2o to solve ICP problems - estimating the transformation relationship between two sets of 3D point sets with matching relationship

【万字长文】使用 LSM-Tree 思想基于.Net 6.0 C# 实现 KV 数据库(案例版)

ESP8266-Arduino编程实例-开发环境搭建(基于PlatformIO)

3Dunity游戏项目实战——飞机大战

新来个技术总监要我做一个 IP 属地功能~

mother

702马力破百仅4.5秒!最强皮卡来袭,安全、舒适一个不落

Load orb dictionary
随机推荐
《微信小程序-进阶篇》Lin-ui组件库源码分析-Button组件(一)
Access rights - private, public, protected
Build neural network from simple to deep
PostgreSQL在Linux和Windows安装和入门基础教程
外包干了四年,废了...
ISO 639:1988 : Code for the representation of names of languages
-bash: ./build. Sh: /bin/bash^m: bad interpreter: no that file or directory
Introduction to authoringrealm
[idea]如何新建一个项目
36. [difference between const function and function]
Scrapy ip代理无响应
Several ways of communication between threads
702 horsepower breaks through 100 in only 4.5 seconds! The strongest pickup truck comes, safe and comfortable
Caused by: scala.MatchError: None (of class scala.None$)
Dichotomous template summary
js使用WebUploader做大文件的分块和断点续传
AuthorizingRealm简介说明
easyui01
浅谈VIO之IMU预积分(还是刚入门时的想法)
Real time streaming protocol --rtsp