SQL Basic Operations

Source: Internet
Author: User
Tags mssqlserver

A data type
1 integer int
2 exact numeric decimal (N,P) n is the total number of digits, p is the number of decimal digits
3 Float type float
4 char (n) n Max is 4,
VARCHAR (n)
5th-year Datatime
6 Text Type


Two basic operations
1. Locate the primary and log files for your database:
Right click on the database, click Properties, click File.
2. Create a new database:
Right-click the database, create a new database, enter a name for the database
3. Create a new database with a statement:
Click New query, enter a statement in the window and click Execute
Create DATABASE Lianxi--linxi for the DB name
Go
4. Use the database and create a table to add column names to the table
Use Lianxi
Go
CREATE TABLE Shucai--shucai is the name of the table.
(
The code int NOT NULL,--the NOT NULL is not empty.
Name varchar () is not NULL,
Price Decimal (18,2),
Chandi varchar (10),
Shuliang Decimal (18,2),
)
Go
5 Adding data
INSERT into SHUCAI values (1, ' cabbage ', 0.5, ' Zibo ', 100)
INSERT into SHUCAI values (2, ' radish ', 2, ' Binzhou ', 200)
INSERT into SHUCAI values (3, ' celery ', 0.8, ' Zibo ', 300)
INSERT into SHUCAI values (4, ' garlic ', 5, ' Binzhou ', 500)
INSERT into SHUCAI values (5, ' canola ', 0.6, ' Yantai ', 600)
INSERT into SHUCAI values (6, ' herring ', 4, ' Zibo ', 800)
INSERT into SHUCAI values (7, ' potatoes ', 0.9, ' Zibo ', 700)
Go
6 Finding data
Select *from Shucai--Find all data
Select Top 3 *from shucai--Find first 3 rows of data
Select *from shucai where code= ' 2 '--Find all the information for code 2
Select Name,price from Shucai where code= ' 3 '--Find the name and price information for code 3
Select Price from Shucai where name= ' cabbage '--Find the price information for name cabbage
Select Name,price from Shucai--Find table name and price columns
7 Modifying data
Update Shucai set price= ' 1 ' where code= ' 7 '--Modify the price of code 7
Update Shucai set price= ' 5 ' where name= ' herring '--change the price of name to Herring

8 Deleting data
Delete from Shucai where code= ' 2 '--deletes this line of code 2.

Three database files:
The primary file stores data, the boot information must have, and only one. mdf

Secondary file Store the number of primary files that are not stored is optional and can be as few as possible. ndf

Log file Logging operation information must have and at least one. ldf

Quad Run cmd

Input net start MSSQLserver start database service

Enter net stop MSSQLserver to shut down the database service

SQL Basic Operations

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.