sql02

1、小练习:

一切数据都是有用的,当我们删除时只是象征性设置一个标志位:

2、SQL学习

1)创建数据库

create database DbName;

使用--注释

多行注释/**/

2)删除数据库

drop database DbName;

3)其他设置:

4)查询:(注意必须加[])

select * from [Demo].[dbo].[user];

5) 创建表

create table Employee(
    Id int primary key not null,
    EmpName nvarchar(32) null,
    EmpAge int default(18) not null,
    DelFlag smallint default(0) not null
)

primary key  设置主键

not null  设置不可为空

default() 设置默认值

->创建数据库的SQL:********
        create database 数据库名
        on
        (
            name=‘’,
            size=5MB,
            filegrowth=2MB,
            filename="....datadb.mdf"
        )
        log on
        (
            name=‘_log’,
            size=5MB,
            filegrowth=2MB,
            filename="....datadb_log.ldf"
        )
    ->创建表的SQL:*******
        create table 表名
        (
            列名 类型 null,
            .....,
            列名  类型 primaryt key not null,--主键列
            
            列名  类型 identity(1,1) not null,--自动增长,只能用于数据的类型:int,bigint,float
            
        )
--设置种子与自动增长
Id int identity(1,1) not null

6)基本查询

查询某几列

select name,age from [dbo].[user];

指定条件:where

select name,id from [dbo].[user] where name='Lucy';

7)插入

Insert into [表名](列名1,列名2,...) values(值1,值2...)

Insert into [user](name) values('Oliva');

如果插入中文字符,需要声明N,

省略了结构名dbo,而且只有dbo可以省

Insert into [user](name) values(N'李慧霞');
Insert into [user](name,birthdate) values(N'孙兴','1997-9-8');

8) 删除

 如果没有where进行条件限制,将删除整个表

delete from [dbo].[user] where id=3;

9) 修改

update [dbo].[user] set name='cc',age=12 where id=3

->NChar和Char的区别?
->避免乱码
->N:Unicode,用两个自己表示一个字符。

字节不同 char类型是一个字节char(8)只能存8字母; nchar类型是双字节nchar(8)能存8个汉字;

原文地址:https://www.cnblogs.com/Tanqurey/p/12394582.html