1: drop
use accounting
drop table MERs
delete a table
use master
drop database accounting
delete a database
here, the database is deleted using the master.
you must close the external connection to delete the database.
2: create
first look at the example
Create Database accounting
On
(name = 'accounting ',
filename = 'C: \ database \ accountingdata. MDF ',
size = 10,
maxsize = 50,
filegrowth = 5)
log on
(name = 'accountinglog ',
filename = 'C: \ database \ accountinglog. ldf',
size = 5 MB,
maxsize = 25 MB,
filegrowth = 5 MB)
go
the complete create database syntax has many clauses.
the example I wrote above only involves several common clauses.
The following explains:
On refers to the location where data files are stored. data can be stored in multiple files (this is only applied to super large databases).
name is the logical name of the file, this parameter is used to adjust the size of the database file
optional filename parameter. If this parameter is not used, this file is stored in the mssql.1 \ MSSQL \ data directory
if it is a data file, the name is the same as the database name, and the extension is. MDF
if it is a log file, the name is the database name followed by a _ log, and the extension is. LDF
size of the database, which can be an integer or an integer, but cannot be a decimal number.
if this parameter is not set, this is the disk size. We recommend that you set a number that is smaller than the disk size.
the number of the filegrowth database to increase each time, which can be an integer and a percentage
log on is used to set logs, by default, the log file is 25% of the data file size.
it is recommended that log files and data files be stored on the same disk to avoid competition and ensure security.
Create Table
First look at the example
Use Accounting
Create Table MERs
(
Id int idetity not null primary key,
Username varchar (30) not null
)
I won't say much about it.
Naming Conventions
1: Keep the name brief. The length must be sufficient to make the name descriptive.
2: When constructing a table based on other tables, the name of the new table contains the name of the parent table.
3: When there are two words in the name, do not use any separator, the first letter of each word is capitalized
Iii. Alter
Alter database accounting Modify file (name = accounting, size = 100 MB)
The above is to extend the database file to 100 MB
Alter table customers add fedid varchar (9) null
Alter table customers add
Contact varchar (25) null,
Lastraisedate datetime not null default '2017-12-4'
The following alter statement about the primary key
use accounting
alter table employee
Add constraint pk_employeeid
Primary Key (employeeid)
to add constraints to the table,
name of the constraint
type of the constraint
columns to which the constraint is applied