当前位置:网站首页>Basic database syntax learning

Basic database syntax learning

2022-06-24 21:09:00 GS_ Qiang

One . New database

1. Graphical interface manual creation
Right click database – New database
2. Use code to create
 New database
3. There is also a syntax for creating a database , Specify database file parameters and log file parameters , The grammar is as follows :create database Database name on [primary] ( < Data file parameters > [,…n] [< Filegroup parameters >] ) [log on] ( < Log file parameters > [,…n] )

Two . new table

1. Graphical interface manual creation
Right click table – new table
2. Use code to create
 new table
3. Methods for inserting data into tables :
(1) Insert a piece of data (4 Methods ):
 Insert data method
(2) Insert multiple data :
 Insert multiple data
(3) Insert a new column name :
 Insert picture description here
(4) Copy table to new table
 Insert picture description here

matters needing attention

(1): Insert one row at a time , It is impossible to insert only half a row or a few columns of data , therefore , Whether the inserted data is valid will be checked according to the integrity requirements of the whole row ;

(2): The data type of each data value 、 The precision and scale must match the corresponding column ;

(3): Cannot specify value for identity column , Because its number increases automatically ;

(4): If a column is specified when designing the table, it is not allowed to be empty , Data must be inserted ;

(5): Inserted data item , It is required to meet the requirements of inspection constraints

(6): Columns with default values , have access to default( default ) Keyword instead of the inserted value

4. Delete operation :
 Delete operation
Be careful
The operation of deleting the whole table is compared with that of emptying the whole table
Delete is to delete all , Including table structure
Emptying just empties the data in the table , But the table structure is still , Empty faster

5. Delete database :
 Delete database

6. modify

 Change

7. Inquire about
 Inquire about

3、 ... and . data type

1. Numeric type
bight -263~262-1
int -231~231-1
smallint -215~215-1
tinyint 0~255
float -1.79E+308-2.23E-308 as well as 2.23E-3081.79E+308

2. Time type
time 12:35:29.123456
date 2007-05-08
smalldatetime 2007-05-08 12:35:00
datetime 2007-05-08 12:35:00.123
datetime2 2007-05-08 12:35:00.1234567

3. String type
char[(n)] Fixed length .n Used to define the string length , And it must be 1~8000 Between the value of the
varchar [(n|max)] Variable length .n Used to define the string length , And it can be 1~8000 Between the value of the
nchar[(n)] Fixed length Unicode character string 1 data .n Used to define the string length , And it must be 1~4000 Between the value of the
nvarchar[(n)] Variable length Unicode character string 1 data .n Used to define the string length , And it can be 1~4000 Between the value of the

notes : In general use varchar and nvarchar, You can save memory

 Insert picture description here

Reference link

原网站

版权声明
本文为[GS_ Qiang]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202211319023223.html