Usage Server basic statement

1. Create a database

create database databaseName

user databaseName

go / * Go to the specified database * /

2, create a table

create table tableName(

/*

Field name

*/

)

3, insert data

insert into tableName values ​​( '', '', '', '', '', ',',); / * there is a need to insert bracket data * /

4, create a primary key

alter table tableName add constra py_tableNameId primary key (tableNameId) / * py_tableNameId: Name; tableNameId: primary key name to be set * /

5, the foreign key added

alter table tableNameA add constra py_tableNameId foreign key (tableNameAId) references tableNameB (tableNameBId) / * py_tableNameId: Name; tableNameAId: foreign keys to be set, tableNameBId: field name associated with the need * /

6: Modifying Data

update tableName set Field name = '' WHERE condition (field = '')

7: Query Data

    select * from tableName / * query all the data * /

    select * from tableName where conditions / * condition query all fields * /

    select top 10 from tableName / * look-up table 10 before the data or query by the conditions of the first 10 data * /

    select top 10 from tableName where the condition / * query by the conditions of the first 10 data * /

   select distinct field names from tableName "; // queries do not duplicate data

8, delete data

   delete from tableName where conditions / * Delete Row * /

   delete from tableName / * Delete all rows * /

   drop tableName / * Delete table * /

9, plus add fields:
   the ALTER the Table tableName the Add Column Name varchar (20) 10, delete the field

  alter table tableNamedrop  column  字段名;
 
 
 
 
 
 
You can refer to: https: //jingyan.baidu.com/article/c33e3f48d63800ea15cbb5cb.html additions and deletions to change search this site in great detail

 

Guess you like

Origin www.cnblogs.com/my1227/p/11233013.html