SQL server commonly used commands

This article reprinted from: https: //www.cnblogs.com/yuzhonghua/p/7612594.html

sql server database commonly used commands

Create a database:

   Command: create database database name;

  Example: create database student;

Delete the database:

  Command: drop database database name;

  Example: drop database student;

New Form:

  Command: create table table name

              (Column name data type, column names 2 .....)

  Example: create table student

             (sname  char(20),sid  int)

Delete table:

  Command: drop table table name

  Example: drop table student

Modify table structure:

    (Insert (new) column)

    Command: alter table table name

                 add new column name Data type

    Example: alter table student

                 add  sage  int

    (Delete the column)

    Command: alter table table name

                   drop column 列名

    Example: alter table student

                   drop column sid

    (Modified column type)

    Command: alter table table name

                  alter column name data type column

    Example: alter table student

                  alter column sid float (float)

  (New constraint)

     Command: alter table table name

                  alter column column names new data types

     Example: alter table student

                   alter column PK_sid primary key (sid) (the new primary key constraint is a constraint type)

  (Delete constraints)

    Command: alter table table name

                  drop column names

    Example: alter table student

                  drop PK_sid

Query table of contents:

  Command: select the data to be queried column names

              from table

                where filter criteria (packet data can not be screened)

(Advanced Search) [group by the column name (packet)

                         having filters (only the data packets to filter)

                            Sort order by (the arrangement of the control data are the final output of the positive sequence: asc, flashback: desc)]

  Example: select sid

             from student

               where  sid=2

                    【group by sid

                              having  sid=1

                                   order by desc】

Inserting the data value in the table and column must correspond :()

 Command: insert into table

                (Column name, column name)

            values

                (Value, value)

  Example: insert into table

                (sname,sid,sage)

            values

               ( 'John Doe', 12, 15)

Modifying the data values ​​in the table:

  Command: update from the table name

               set new column name = value

  示例:update from student

              set sname = 'John Doe'

Query mode :( bulk insert multiple data)

  Command: (Total number of values ​​must be the same and columns) insert into table

                select value, value, value union all

                selevt value, value, value

  Example: insert into table

               select 'John Doe', 15, 18

               select 'John Doe', 16, 19

view:

  Command: create view view name

              as

             select Column

             from table

  Example: create view students

              as

                 select sname

                     from student

Released six original articles · won praise 1 · views 646

Guess you like

Origin blog.csdn.net/KID__77/article/details/104940289