Database June 10, 2014 08:17:28

Source: Internet
Author: User
Tags logical operators

There may be two meanings to the "database": MSSQLServer, Oracle, and other DBMS ( software ); A taxonomy catalog ( database file ) that holds a bunch of data tables.

SQL----Structured Query Language, structured queries language. SQL! = SQL Server! = MS SQL Server (MicroSoft)

The primary KEY (PrimaryKey)--- a unique identifier for each data row in a table, and is unique and non-empty . There is no duplicate value---cannot be null---there is only one (no composite primary key involved).

Business Primary key is the use of business-meaningful field key, such as a social Security number, bank account, etc. logical primary KEY ( recommended ) is to use a field without any business meaning the key, completely to the program, the business people will not look at the data.

A database file exists in the offline---software----is restored by online, separated---No database file exists---by additional restore.

Backup and restore of the database: Restore----Right-click the database file---task, restore the database----source device, select the backup file. * The option "Overwrite existing database" must be checked .

Data type:bit (bool type) the database is stored in true and FALSE,SQL statements are represented by 1 and 0; thedatetime type is entered in a single quotation mark in the SQL statement;

Char type Fixed length (Space supplement) Not included in Chinese 8000 characters Maximum
VARCHAR type Variable length Not included in Chinese 8000 characters Maximum
nvarchar type Variable type Can include Chinese 4000 characters Maximum

The strings in the SQL statement are enclosed in single quotes and are case insensitive ( keywords + database name + table name + column name ).

The function newid () that generates the GUID in SQL Server. The method for generating GUIDs in Net is Guid.NewGuid () and the return type is the GUID type.

"1"insert into table name (column 1, column 2---) values (value 1, value 2---); column names and values must one by one correspond.

Insert into table name values (value 1, value 2---), omit column names, the values should have corresponding values (other than the identity column ) for the other columns ( with default values ).

"2"update table name set column name = new value where column name = old value.

"3"delete from table name where column name = a value. -----Delete and truncate differences: The former is emptied, but the primary key does not start at 1, the latter empties the data, restores the identity column, and starts at 1.

"4"drop table name. ------Drop and delete:drop is to delete the entire table; Delete is the data in the table, but the table is still there.

"5"select column name from table name where to judge. ------Select Number as, name as name, age as ages from student: As is an alias to a column in the result set

OrderBy---this sentence is at the end of the SELECT statement and word order is sorted by one or more columns----default to ascending ASC, (DESC)-----SELECT * FROM Employee ORDER by age Desc,salary ASC, first by age from the big to the small row, the same age by salary from low to high rank.

Other logical operators that can be used in where : Or, and, not, <, >, >=, <=,! = (or <>), and so on.

(sequencing)

where+group By:group By+having: filter the data after grouping. where+group By+having:select Name,sum (Salary) from employee where name= ' Bush ' or name= ' Adas ' group by name having sum (Salary) >1500 to find the name of the employee table in which the name "Bush" or "Adas" is paid more than 1500.

Federated Result set : Union is efficient underground because it is being scanned for duplicate values, so if you are not sure that you want to merge duplicates, it is recommended that you use UNION ALL.

Wildcard: must be used with a like. The word wildcard "_"; a multi-character wildcard "%" that matches any length (0 or more) of any number of occurrences (0 or more); [] a character within the range specified in the parentheses-----[AO] represents a and o two; [^] a character that is not in the brackets.

The difference between null in C # and the database : In C #, a variable is assigned null, indicating that the variable does not point to any object, and that the null representation in the database is not known, not not. ------SELECT * from the employee where name is null-----The IS keyword when the name is null .

Between: used in the WHERE clause, select * FROM employee where name between ' Adas ' and ' Salar '----------SQL Server will list names between ' Adas ' and ' Salar ' and includes those two values .

In keyword: The in operator allows us to specify multiple values in the WHERE clause; SELECT * from Persons where LastName in (' Adams ', ' Carter ')----- Select the person whose last name is Adams and Carter from the table.

remove duplicate data and return only different values.

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.