11-10(11-10)

sql基础、SQL Server 的数据类型、常见约束 SQL 语句种类:

    (1)DDL(Data Definition Language,数据定义语言):创建、删除或修改数据库以及数据库中的表等对象。

      ①CREATE:创建数据库和表等对象

      ②DROP:删除数据库和表等对象

      ③ALTER:修改数据库和表等对象

    (2)DML(Data Manipulation Language,数据操作语言):查询或修改表中的记录。

      ①SELECT:查询表中的数据

      ②INSERT:向表中插入数据

      ③UPDATE:修改表中的数据

      ④DELETE:删除表中的数据

    (3)DCL(Data Control Language,数据控制语言):确认或取消对数据库中的数据变更的执行操作,以及对用户的操作数据库中的对象权限进行设定。

      ①COMMIT:确认对数据库中的数据进行的变更

      ②ROLLBACK:取消对数据库中的数据进行的变更

      ③GRANT:赋予用户的操作权限

      ④REVOKE:取消用户的操作权限

判断数据库是否存在如果存在删除这个

if exists(select * from sys.databases where name=’数据库名’)–判断test是否存在如果存在删除这个drop database 数据库名gocreate database 数据库名

SQL Server 的数据类型

常见约束

not null:非空约束,指定某列不为空unique: 唯一约束,指定某列和几列组合的数据不能重复primary key:主键约束,指定某列的数据不能重复、唯一foreign key:外键,指定该列记录属于主表中的一条记录,参照另一条数据check:检查,指定一个表达式,用于检验指定数据

————————

Basic SQL, data types of SQL server, types of common constraint SQL statements:

(1) DDL (data definition language): create, delete or modify databases and tables in databases.

① create: create objects such as databases and tables

② drop: delete database, table and other objects

③ alter: modify database, table and other objects

(2) DML (data manipulation language): query or modify the records in the table.

① select: query the data in the table

② insert: insert data into the table

③ update: modify the data in the table

④ delete: delete the data in the table

(3) DCL (data control language): confirm or cancel the execution of data changes in the database, and set the user’s operation object permissions in the database.

① commit: confirm the changes to the data in the database

② rollback: cancel the changes to the data in the database

③ Grant: operation authority granted to users

④ revoke: cancel the user’s operation permission

Determine whether the database exists. If so, delete the database

if exists(select * from sys.databases where name=’数据库名’)–判断test是否存在如果存在删除这个drop database 数据库名gocreate database 数据库名

Data type of SQL Server

Common constraints

Not null: non NULL constraint, specifying that a column is not empty. Unique: unique constraint, specifying that the data of a column and several columns cannot be repeated. Primary key: primary key constraint, specifying that the data of a column cannot be repeated and unique. Foreign key: foreign key, specifying that the column record belongs to one record in the main table and references another data. Check: check, specifying an expression, Used to verify specified data