SQL Server database code basic operations

- Create a database by way of the code of
the Create Database MyDatabase
ON Primary
(
- name
name = 'MyDatabase_data',
- path
filename = 'F: \ Cesoft \ the Data \ MyDatabase_data',
- the size of the
size = 5MB,
- growth
filegrowth 1MB =
)
log ON
(
- name
name = 'MyDatabase_log',
- path
filename = 'F.: \ Cesoft \ the Data \ MyDatabase_log',
- size
size = 1MB,
- growth
FILEGROWTH = 10%
)


 

- code creates a table entry
Create Class Table
(
the ClassId int Identity (1,1) Primary Key,
ClassName nvarchar (10),
ClassDesc nvarchar (20 is)
)

- Create a table table
- Primary Key
- ID table
- table description information
- Remarks table
- 1-- identification 0--2-- predetermined idle use
- the table creation time
create DeskInfo Table
(
DeskId int Identity (1,1) Primary Key,
DeskNumber nvarchar (10),
DeskDesc nvarchar (10),
DeskRemark nvarchar (10),
In Flag int,
DeskStarDateTime datetime
)


 

- adding data codes

- a first mode
insert into table (1 column names, column names, 2) values (value 1, value 2)
insert into Class (ClassName, ClassDesc) values ( 'high class a 1', 'science experiment class')
- the number of rows affected by the addition of data

- A second
insert into table values (value)
insert into Class values ( 'a high class 2', 'science experiment class')

- a third mode, a plurality of data insertion disposable
insert into Class values ( 'a high class 3', 'science experiment class')
insert into Class values ( 'a high class 4', 'science experiment class')
INSERT into Class values ( 'a high class 5', 'science experiment class')

- A fourth embodiment
INSERT INTO Class (ClassName, ClassDesc)
SELECT 'a high class 6', 'arts experimental class' Union
SELECT 'a high class 7', 'arts experimental class' Union
SELECT 'a high class 8', 'liberal arts experimental class'


 --change the data

* from Class SELECT
Update table set value = 1 column 1, column 2 = 2 value
update Class set ClassDesc = 'experimental class'
- modifying or updating the data in the table is the number of returned rows affected
update Class set ClassDesc = 'regular classes' where ClassId = 1


 

- delete
- add and modify the return lines are affected by the number of impact

- First, the data is gone, the table still, but then id delete id before continuing plus 1
the Delete from Class
- the second, not the table, the data did not
drop the Table Class
- Third, table exists, the data is not, id start from 1 (high)
TRUNCATE table class


 

Guess you like

Origin www.cnblogs.com/bule-comet/p/11791859.html