Create a database
CREATE DATABASE database_name
Example: CREATE DATABASE Test
Execute commands first when creating a table
Use test
Create a table
CREATE TABLE table name (column name 1 data type, column name 2 data type, ... )
Example: Create table book (name char), writer varchar (20))
You can set some fields to be self-increment when you create a table, but the field property must be of type int
The CREATE TABLE table name (column name int identity (A, b)) A represents the increment starting from a,
Increase the B value each time (note that both A and B must be int and cannot set the word length)
Example: Create TABLE book (book_id int identity)
Inserting data into the table
Insert into Table name values (field value, field two value, ...)
Example: INSERT into book values (' Wolf totem ', ' Jiangrong ')
Note the field values of the varchar and char types are inserted in single quotation marks
To modify the data type of a column in a table
ALTER TABLE name ALTER COLUMN name new data type
Example: ALTER TABLE book ALTER COLUMN varchar (20)
Delete all field values in a table
Delete Table name
Example: Delete book
Delete a table
DROP table Name
Example: Drop book
View the details of a table
sp_help table Name
Example: Sp_help book
Copy all of the data from table 1 to table 2:
INSERT INTO table1 select * from table2
Common commands used by SQL Server