1201 New Course TSQL Statement

Source: Internet
Author: User

1. Create a database

Create Datebase table name

2. Deleting a database

Drop Datebase Table Name

3. Create a table

-CREATE TABLE Test (table name)
(
Code(column name) varchar(column type, string type)(string length),
Name varchar (20)
);

-CREATE TABLE Test1
(
Code varchar ( primary key),
Name varchar (20)
);

Primary KEY Primary Key

CREATE TABLE Test2
(
Code varchar (primary key),
Name varchar (not null )
); NOT NULL non-null

-CREATE table Zhu
(
Code int PRIMARY KEY,
Name varchar (20)
);
CREATE TABLE Cong
(
Code int PRIMARY KEY,
Name varchar (20),
Zhu Int,
Foreign key (Zhu) references Zhu (code)
);

Foreign key (column name) references primary table name (column name) foreign key

CREATE TABLE Haoyou
(
IDS int Auto_increment primary KEY,
Me varchar (20),
Friends varchar (20)
);

Auto_increment Self-growing column

Note: 1. Add a semicolon after each statement
2. The last column is followed by a comma
3. The symbol must be in English

To change the data and to search and delete
CRUD Operations
C:create add
R:read Query
U:update modification
D:delete Delete

1.C: Add Data
Insert into table name values (' n001 ', ' Zhang San ');

INSERT into test2 values (' n001 ', ');
INSERT into Test2 (code) VALUES (' n001 '); Specify columns to add
INSERT into haoyou values (' Zs ', ' ls ');

Attention:
1. If the added data is a string, you need to add < single quotation marks, if it is another type do not add single quotation marks 2. When adding data, the number of values matches the column
3. When adding data, you can specify a column to add
4. If the column you want to add is a self-growing column, you can give an empty string

5. Comment Syntax: #

CRUD Operations
1. Increase
Insert into table name values (column values, column values)
Insert into table name (column name, column name) values (value, value)

2. Delete
Delete from table name
Delete from test

Delete from table name where condition
Delete from test where code= ' n002 '

3. Modifications
Update table name set column name = value
Update test set name= ' hui '

Update table name set column name = value WHERE condition
Update test set name= ' Han ' where code= ' n002 '

1201 New Course TSQL Statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.