欢迎投稿

今日深度:

Server基本语句的用法,

Server基本语句的用法,


1、创建数据库

create database databaseName

user databaseName

go   /*  转到指定数据库 */

2、创建表

create table tableName(

/*

字段名

*/

)

3、插入数据

insert into tableName values('','','','','',',',);  /* 括号里面是需要插入的数据 */

4、创建主键

alter table tableName add constra py_tableNameId primary key (tableNameId)   /*   py_tableNameId: 名称;tableNameId:需要设置的主键名*/

5、添加外键

alter table tableNameA add constra py_tableNameId foreign key (tableNameAId) references  tableNameB (tableNameBId) /*   py_tableNameId: 名称;tableNameAId:需要设置的外键名,tableNameBId:需要关联的字段名*/

6:修改数据

update tableName set 字段名=‘’ where  条件(字段名=‘ ’)

7:查询数据

    select * from tableName   /*查询所有的数据*/

    select  * from   tableName where 条件  /* 条件查询所有字段 */

    select top 10 from tableName   /*  查询表中前10条数据 or  按条件查询前10条数据*/

    select top 10 from tableName  where 条件  /*  按条件查询前10条数据 */

   select distinct 字段名 from tableName ";//查询不重复的数据

8、 删除数据

   delete from tableName where 条件   /* 删除行 */

   delete from tableName  /* 删除所有行 */

   drop tableName  /*删除表*/

9、添加加字段:
   alter table tableName add 列名 varchar(20)10、删除字段

 alter table tableNamedrop column 字段名;             可以参考:https://jingyan.baidu.com/article/c33e3f48d63800ea15cbb5cb.html   这个网站的增删改查很详细

 

www.htsjk.Com true http://www.htsjk.com/Sql_Server/29690.html NewsArticle Server基本语句的用法, 1、创建数据库 create database databaseName user databaseName go /* 转到指定数据库 */ 2、创建表 create table tableName( /* 字段名 */ ) 3、插入数据 insert into tableName values('','','',...
相关文章
    暂无相关文章
评论暂时关闭