Relational database study notes

This article is divided into three parts, concepts, mysql, sqlserver

part1 concept

Chapter One Introduction

Four concepts:
Data: Data Express
Database: DataBase logistics warehouse
Database management system: DBMS entire warehouse operation
database system: DBS entire logistics system
Conceptual model: ER diagram
Oval: Attribute
Rectangle: Entity
Diamond: Contact
1: N: One-to-many
N: N: Many-to-many
Logical physical model:
Hierarchical model: Tree
Network model: Graph
Relational model: Two-dimensional table
Relation: One table
Tuple: One row
Attribute: One column
code: The attribute set of a tuple can be uniquely determined and Its proper subset is not a code (multiple attributes can be used as codes)
Candidate code: a very small super code set, any of its proper subsets is not a super code, and it is a super code
master code: the master code is selected to be used in one Candidate codes for distinguishing different tuples in the relationship
Domain: attribute value range
Component: cell value
Relation mode: description of the relationship
Integrity constraint:
entity integrity: the main code is unique and non-null
Referential integrity: outer code or empty , Or the master code of another table.
User-defined integrity: user-defined
three-level mode and two-level image:
application—n:1—outer mode—outer mode/mode image n:1—mode (that is, logical mode) )
Mode—Internal Mode/Mode Map 1:1—Internal Mode—1:1—
Data Independence:
Logical independence: When the mode structure changes, only the external mode/mode image needs to be modified to maintain logical independence.
Physical independence: When the internal mode structure changes, only the mode/internal mode image needs to be modified to maintain physical independence

Chapter 2: Relational Database

Relation: a table
Relation description: R(U,D,DOM,F)
R: Relation name
U: All attribute names
D: Which domains the attribute comes from
DOM: The mapping
between attributes and domains F: Dependency relationship
between attributes Operation: Add, delete, modify and check
query operations: select, project, join, divide, union, difference, intersection, Cartesian product
Relational data language: relational algebra language, relational calculus language, SQL language
Relational algebra language:
and: I have or you have
: Take the same
difference: Take what I have you don’t.
Cartesian product: Combine each of my tuples with each of your tuples.
Selection: the tuples whose components are within the set range.
Projection: Selection column.
Connection:
Natural connection: Common. The attributes are equi-connected, and the discarded tuples are called floating tuples
(full) outer joins: on the basis of natural joins, plus the floating tuples in the
left and right tables. Left outer joins: on the basis of natural joins, add the left table The tuple in (the right table attribute of the tuple is empty)
right outer join: on the basis of natural connection, plus the tuple in the right table (the left table attribute of the tuple is empty)
division: as shown in the figure

Chapter 3: SQL

Storage file-basic table-view

Check SELECT... select
define CREATE, DROP, ALTER... create, delete, modify
view VIEW, schema SCHEMA, table TABLE, index INDEX, note that the mode and view do not support modification.
Manipulate INSERT, UPDATE, DELETE... insert, update, delete
Control GRANT, REVOKE... the right

Chapter 4: Security

User identity authentication: static password, dynamic password, biometrics, smart card
Access control
Autonomous access control method
Authorization: grant grant and recover revoke

View mechanism (hidden if not used)
audit (all operation records, see if there is any illegality)
data encryption (plain text and cipher text)

Chapter 5: Completeness

Integrity: data correctness and compatibility
Three major integrity: entity, reference, user-defined
user-defined integrity: non-empty NOT NULL, column value is unique UNIQUE, satisfies a certain condition expression CHECK
assertion assertion: specify general constraints , Any operation that makes the assertion not true will be rejected.
Trigger: A special event-driven process defined by the user on the relational table cannot be defined on the view

Chapter 6: Relational Database Theory

There are problems: data redundancy, insert/delete/update abnormal (multiple tables have common attributes)
function dependency:
X can be derived from Y, and Y belongs to X, then X->Y is a trivial function dependency (X class, Y students )
X can be derived from Y, and Y does not belong to X, then X->Y is a non-trivial functional dependency (X class, teacher Y)
X can be derived from Y, but Y is not completely dependent on X, then Y is partially functionally dependent on X ( X student number, surname, Y name)
X can be derived from Y, but for any proper subset of X, Y cannot be derived, then Y is fully functionally dependent on X (X student number, Y name)
Candidate code: a set of attributes , All attributes can be inferred, but any proper subset cannot infer all attributes
such as F (A->B, B->C, D->E, E->D), then AD and AE are candidate codes, pay attention to candidate codes not necessarily the only
solution if the candidate topic ideas code: appears only on the left must be, must not only appear on the right, the left and right do not necessarily appear
and then may be assumed to be a candidate in the by-code to try
super Size: it can represent attributes Attribute set
Candidate code: the smallest super code, the true subset of the candidate code cannot deduce all attributes.
Master code: pick one of the candidate codes as the main code.
Main attribute: the attribute contained in any candidate code is
not the main attribute: No Attribute
code included in any candidate code : We call the main code and candidate code the code.
Full code: All attributes are codes, which is the full code.
Normalized paradigm
1NF: All relational patterns are 1NF, and no table in the table is
enough 2NF : On the basis of 1NF, there is no partial functional dependence of non-primary attributes on the code. In simple terms, it is completely dependent on
3NF: On the basis of 2NF, there is no transfer function dependence of non-primary attributes on the code. rely
BCNF: On the basis of ENF, there is no main attribute to the code part and transfer function dependence, in simple terms, it is completely directly dependent between the main attributes.
Data dependence axiom system
Reflexive law: Y belongs to X, then X can derive Y's
augmentation law : X can be introduced into Y, then XZ can be derived from YZ
transfer law: X can be
derived from Y, Y can be derived from Z, then X can be derived from Z. Merger rule: X is derived from Y, X is derived from Z, and X is
derived from YZ pseudo-transfer rule: by X pushes Y, WY pushes Z, and XW pushes the Z
decomposition rule: X pushes Y and Z belongs to Y, then X pushes Z.
Questions: Find the minimum functional dependency set: Each dependency in F cannot be introduced by other dependencies , And the right side must be a single-element
solution: delete one by one to see if it is redundant, and note that the answer may not be unique.
Mode decomposition
Criterion: Lossless connectivity, maintain functional dependency
Test question: How to decompose the database into 3NF, and maintain lossless decomposition and functional dependency

Chapter 7: Design

Demand analysis
Conceptual structure design: ER diagram, data dictionary
Logical structure design: Convert ER diagram into logical model: 1 to 1 conversion main code, 1 to N conversion external code, N to N table
physical structure design: logical model conversion to Physical model
Database implementation: writing SQL code
Database operation and maintenance: performance testing, dumping, and recovery

Chapter 8: Programming

Embedded SQL: write SQL into other programming languages ​​(pre-programmed variable function, main function recompiled).
Main variable: variable passed in by the main language used by SQL, such as: name (note that there is:)
Cursor: a buffer for storage SQL execution results
Dynamic SQL: Determine the SQL clauses
during execution, use dynamic SQL procedures SQL: Basic block structure
Definition part: DECLARE variables, constants, cursors, exceptions
Execution part: BEGIN: SQL statement, procedural SQL process
control statement: EXCEPTION The exception handling part of the END
stored procedure and function is similar, except that the former has no return value, and the latter must have
ODBC programming

Chapter 9: Relational Query and Optimization

Algebraic optimization: first select and project, and finally connect

Chapter 10: Recovery Technology

Transaction: Level 1 SQL statement
A. Atomicity actom: Either do it all or not at all.
C Consistency: The relationship between data remains unchanged.
I Isolation isolate: The execution of a transaction is not interfered by other transactions.
D Persistence duration: Permanently change, write to disk.
Transaction failure:
inside things: adopt REDO and UNDO technology.
System: restart, unfinished UNDO, lost transaction REDO
medium: repair hardware, reinstall database, REDO completed transaction
Virus: antivirus
Recovery technology:
data Dump: re-execute the failed transaction.
Log file: record the update operation file of the transaction to the data
. Recovery with checkpoint

Chapter 11: Concurrency Control

Causes problems:
Lost changes: I read, he reads, I changed, he changed, my changes are lost
Read dirty data: he changed, I read, he rolled back, I read dirty data (Equivalent to different values ​​when
reading later) Non-repeatable reading: I read it, he changed it, and I read it again. The two values ​​I read are different.
Solution:
Exclusive lock=write lock=X lock
shared lock=read Lock=S lock
First-level lockout protocol to solve the lost modification: add X lock until the end of the modification.
Second-level lockout protocol to solve the dirty data reading: add S lock when reading, and put the
third-level lockout protocol to solve the non-repeatable read: read Add S locks until the end
Livelock: the lock waits forever, no chance to lock (low priority starves to death)
Deadlock: multiple locks wait for each other, and no one locks each other.
Serializable scheduling: concurrent scheduling The result of a certain time is consistent with the serial scheduling.
Large block size, low concurrency and low overhead

index

Unique index: Two rows are not allowed to have the same index value.
Primary key index: It is automatically created when the primary key is defined for the table. It is a special type of unique index. The primary key index requires that each value in the primary key is a unique
clustered index: the physical order of the rows in the table The same as the logical (index) order of the key value, the table can only contain one clustered index
(can be understood as the pinyin of the dictionary, sorted in dictionary order, the implementation method has B/B+ tree, in theory, it can also be binary search)
non-clustered Index: The data and index contain points to the corresponding location of the data storage. The physical order of the rows in the table does not match the logical order of the key value
(it can be understood as a map. Some frequently accessed data addresses in the table are used as the key value to generate a key map. It, search for its key every time)
Among them, the clustered index is faster than the non-clustered index, a table can only have one clustered index, but there can be multiple non-clustered indexes

key

First: clear concept, key, is code, one meaning,
then: super key/super code, candidate key/candidate code, primary key/master code
Super key (super key): the attribute set that can uniquely identify the tuple in the relationship is called The super key of the relational mode
Candidate key: A super key that does not contain redundant attributes is called a candidate key.
Primary key: A candidate key selected by the user as a tuple identifier. Program primary key

For example, the following four attributes (assuming no duplicate names): ID card name, gender, age

The ID is unique, so it is the only super key
(ID, name, name), so it is the only super key
(ID, name, gender), so it is the only super key
(ID, name, gender, age), so Is a super key The
name is unique, so a super key
(name, gender) is unique, so a super key
(name, gender, age) is unique, so it is a super key

ID card is unique and has no redundant attributes, so it is a candidate key.
Name is unique and has no redundant attributes, so it is a candidate key

As a user, I choose one of the two candidate keys as the primary key. For example, the ID card is the primary key.

Primary attribute: the attribute in the candidate key

Six paradigms

The first normal form: the attributes of every relation r are atomic items and indivisible.
For example: name phone...then the phone may have a home phone and a mobile phone, which does not match

The second normal form: R is 1NF, and each non-primary attribute completely depends on the candidate.
For example: student ID, course ID, grade...The grade depends on the candidate key (student ID, course ID), conforming to
such as: student ID, course ID, grade, student name...The student name only depends on the main attribute student ID and exists Partially dependent, inconsistent

The third normal form: R is 2NF, and non-primary attributes have no transitive dependence on any candidate keywords.
For example: Employee ID, Supervisor ID, Supervisor’s Age...The supervisor’s age depends on the supervisor ID, and the supervisor ID depends on the employee ID, which does not match

BCNF: R is 3NF, and there is no transitive dependency between the main attributes.
For example: warehouse ID, storage item ID, administrator ID, quantity...(Warehouse ID) → (Administrator ID), (Administrator ID) → (Warehouse ID), does not meet

Fourth normal form: R is BCNF, and there is no many-to-many relationship in the table.
For example: employee ID, employee phone, employee cell phone... Phone and cell phone are independent of each other. There may be multiple phones and multiple cell phones, so they must be employee ID-number-number type (otherwise, if one ID has 3 phones) 3 mobile phones, need 9 rows to store)

Fifth Normal Form: R is 4NF, re-establishing the original structure from the final structure.
For example: employee ID, employee phone, employee mobile phone (assuming that the phone and mobile phone are both unique)... Must be disassembled into employee ID-employee phone and employee ID-employee mobile phone

Transaction characteristics

Atomicity (self-comparison): Statements in a transaction are inseparable.
Consistency (self-comparison): The transaction must transform the database from one consistent state to another consistent state (similar to atomicity).
Isolation (horizontal comparison): In a multithreaded environment, transactions in one thread cannot be disturbed by transactions in other threads (serializable).
Persistence (vertical comparison): once the transaction is committed, it is saved


part2 mysql

Mysql 查询

select 
{ * | [ distinct ] [ table. ] col [ as name ] [ , [ table1. ] col1 [ as name1 ] , … ] }	
from table [ , table1 , … [ on search_condition ] ]
[ where search_condition ]
[ group by col [ , col1 , … ] ]	
[ having search_condition ]	
[ order by order_expression { asc | desc } [ , order_expression { asc | desc } ]
[ limit m,n ]
[ union [ all ] select … ]

补充:
col部分:可以进行+,-,*,/,%等运算,注意只可以数字相加
可以进行max(col),min(col),avg(col),sum(col),count(col)聚合运算
		char(10)=’yyyy-mm-dd’时,可以使用year(col),month(col),day(col)调用
		timestamp等价于int(14),等价于DATE_FORMAT(col,'%Y%m%d%H%i%s')
		可以使用isnull(col)建列,col为空是1,非空为0
		可以使用nullif(col,val) 建列,col列中值为val的取空,非val取原值
into部分:可以把查询到的内容建成新表
from部分:可以定义要查询的源表,也可以是select子句返回的表
			可以使用left join左外连接,第一个表全部行保留,第二个表只保留匹配行
			可以使用right join右外连接,第二个表全部行保留,第一个表只保留匹配行
			可以使用full join全外连接,两个表都全部行保留,未匹配行全是null
			可以把一个表定义为两个别名,使用自连接
			可以使用cross join交叉连接(笛卡尔乘积)
where部分:可以使用col <,<=,>,>=,=,!=,<>(同!=),可接select子句
				符号可以连接不同的表,若两表同属性名则col部分的列要注明表名
可以使用col [ not ] between … and …
			可以使用not(写在条件前),and,or(三个条件优先级下降)
			可以使用col [ not ] in ( val1 , val2 , val3, … ) 或 val in ( col1 , col2 , col3 , … )
			可以使用col [ not ] like ‘_[a][^b-z]%’( _单符含中文 %全符 []指定 [^]非 )
	可以进行max(col),min(col),avg(col),sum(col),count(col)聚合运算
			可以使用ltrim(col),rtim(col),trim(col),去掉空格
			可以使用clo is [ not ] null
			可以使用[ not ] exists ( select语句) 选择符合条件的行
			可以使用all操作符:<all是小于最小的,>all是大于最大的,=all返回空
			可以使用any操作符:<any是小于最大,>any是大于最小,=any同in
			可以使用some操作符:同any
Group by 部分:可以指定按哪些列分组(可以多列),在col部分可以用count(*)统计
			虽然null不等于null,但是分组中null会分成一组
having部分:类似where定义限制条件,但是其中的聚合函数如AVG只统计组内数据
order by部分:默认asc或1升序,降序设desc或-1,或者用RAND()随机数排序
limit部分:limit m,n可以写成limit n offset m
union部分:连接两个表(列属性名要相同),有all会保留重复值,没有则自动删重复值

执行顺序:from, where, group by, having, select, order by, limit, union, …



Mysql 数据库

创建数据库
create database database_name;
删除数据库
drop database database_name ;



Mysql数据表

创建数据表
create table table_name as select语句
create table table_name ( col1 type , col2 type , … [ condition ] )
	type可以使用int, float, varchar(x), text,其中text可视为无限长的varchar,即x无穷大
	condition可以使用default default_value,设置默认值
condition可以使用primary key,列值必须唯一且不允许有空值
condition可以使用unique,列值必须唯一但允许有空值
condition可以使用not null,不允许有空值
condition可以使用check ( check_condition ),condition例如col>10 and col<20
修改数据表
alter table table_name add col_name type [ condition ]
	增加列
alter table table_name alter column col_name type [ condition ]
	改变列的数据类型
alter table table_name add primary key ( col )
	添加主键(原来不能有主键)
删除数据表
drop table table_name



Mysql视图

创建视图
create view view_name [ ( column_name ) ] as select … [ with check option ] ;
	创建时有with check option字段,则之后通过视图进行数据操作时要也符合定义时的查询条件。
查询视图
select col from view_name;
删除视图
drop view view_name;

对数据表或视图插入数据
insert into { table_name | view_name } ( col1, col2, … ) values ( val1, val2, … ) [ ( val1, val2, … ) ] ;
	对于允许为空的列可以不赋值;有默认值的属性没有赋值时自动设为默认值,可同时插入多行。
对数据表或视图更新数据
update { table_name | view_name } set col = val [ , col1 = val1 , … ] where search_condition ;
	没where就是整列赋值,where子句可以使用其他select子句
对数据表或视图删除数据
delete from { table_name | view_name } where search_condition ;
	没where就是整列删除,注意删除的是行,不可删列。
truncate table table;
	这个不但删了整个表的元素,而所删数据在事务处理日志中还会做相应记录,还比delete效率高。



MySQL导入导出sql文件

window下
1.导出整个数据库
mysqldump -u 用户名 -p 数据库名 > 导出的文件名
mysqldump -u xxxxx -p yyyyyyyy > wwwwwww.sql
2.导出一个表
mysqldump -u 用户名 -p 数据库名 表名 > 导出的文件名
mysqldump -u xxxxx -p yyyyyyyy zzz > wwwwwwww.sql
3.导入数据库(注意sql文件有可能是数据库或表)
source d:/dbname.sql

linux下
一、导出数据库:
mysql的bin目录命令行	mysqldump	-u	用户名	-p	密码	数据库名	>	数据库名.sql
#/usr/local/mysql/bin/   	mysqldump	-u	admin	-p	pass		abcdefg		>	xyz.sql
二、导入数据库
1.当sql文件是一个数据库
mysql	-u	用户名	-p	密码	数据库名	<	数据库名.sql
mysql	-u	admin	-p	pass		abcdefg		<	xyz.sql
2.当sql文件是一个表
(1)选择数据库                    mysql>use abc;
	或者建空数据库				   mysql>create database abc;
(2)设置数据库编码                mysql>set names utf8;
(3)导入数据(注意sql文件的路径) mysql>source /home/abc/abc.sql;



MySQL 连接报错

出现 Authentication plugin 'caching_sha2_password' cannot be loaded
首先登陆,输入密码,然后执行下面四句
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;   #修改加密规则 
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'; #更新用户密码 
FLUSH PRIVILEGES;   #刷新权限 
alter user 'root'@'localhost' identified by 'abccba';



Mysql索引

创建索引
CREATE [ UNIQUE ] INDEX indexName ON table_name (column_name)
ALTER table tableName ADD [ UNIQUE ] INDEX indexName(columnName)
删除索引
DROP INDEX [indexName] ON mytable;
ALTER TABLE mytable DROP INDEX indexName;



Mysql存储过程

创建存储过程
DELIMITER $$
USE `shop`$$
DROP PROCEDURE IF EXISTS `proc`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc`()
BEGIN
  SELECT COUNT(*) FROM goods_type;
END$$
DELIMITER ;
	定义时决定传入与传出参数,有in out inout三种,如上例`proc`( in xx integer)
执行存储过程
Call proc_name();
	传入参数a的话就括号里写@a
删除存储过程
Drop procedure proc_name;



Mysql事务

CREATE DATABASE shop CHARACTER SET utf8 COLLATE utf8_general_ci;
USE shop;
CREATE TABLE `account`(
    `id` INT(3) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(30) NOT NULL,
    `money` DECIMAL(9,2) NOT NULL,
    PRIMARY KEY(`id`)
)ENGINE=INNODB DEFAULT CHARSET=utf8;
INSERT INTO account(`name`,`money`) VALUES('A',2000.00),('B',10000.00);

SET autocommit = 0;
START TRANSACTION;
UPDATE account SET money=money-500 WHERE `name`='A';
UPDATE account SET money=money+500 WHERE `name`='B';
COMMIT;
ROLLBACK;
SET autocommit=1;



part3 sql server

SQL server存储过程

/*创建*/
CREATE PROCEDURE CRE_PRO AS SELECT * FROM brand WHERE cat_name='生鲜食品'
/*执行*/
EXEC CRE_PRO
/*系统存储过程*/
EXEC sp_helptext CRE_PRO
EXEC sp_depends CRE_PRO
EXEC sp_help CRE_PRO
/*修改*/
ALTER PROCEDURE CRE_PRO AS SELECT name,cat_name,cat_id FROM brand WHERE cat_name='运动户外'
/*删除*/
DROP PROCEDURE CRE_PRO



SQL server索引

创建索引
CREATE [UNIQUE] [CLUSTERED|NUNCLUSTERED] //是否唯一索引,是聚类还是非聚类存储
    INDEX 索引名                           //索引名
        ON 表名(属性列……)                  //要生成索列的属性列
            [WITH FILLFACTOR = x]           //生成的索引占总条目的百分比,一般小于30%
使用索引:自动使用
删除索引
DROP INDEX 表名.属性名

举例:
create unique clustered
	index xxx
		on yyy(zzz)
			with fillfactor=30
select * from yyy 
	where zzz 
		between 40 and 60
drop index yyy.xxx




SQL server游标

DECLARE add_cur CURSOR FOR SELECT * FROM user_address	/*声明游标*/
OPEN add_cur                         					/*打开游标*/
FETCH NEXT FROM add_cur            /*执行取数操作*/
WHILE @@fetch_status = 0         	/*判断是否可以继续取数,0成功,非0失败*/
BEGIN								/*while begin … end 是固定搭配*/
  FETCH NEXT FROM add_cur			/* 循环主体就是读取下一行 */
END
CLOSE add_cur                      	/*关闭游标*/
DEALLOCATE add_cur                	/*释放游标*/



SQL server事务

/*启动隐式事务模式*/
SET IMPLICIT_TRANSACTIONS ON
INSERT INTO goods_type VALUES(34,'雪地鞋')
INSERT INTO goods_type VALUES(35,'护手霜')
COMMIT TRANSACTION --提交事务
/*下面的INSERT语句将开始第二个事务*/
INSERT INTO goods_type VALUES(36,'薯片')
SELECT * FROM goods_type
COMMIT TRANSACTION --结束事务
/*关闭隐式事务模式*/
SET IMPLICIT_TRANSACTIONS OFF

BEGIN TRANSACTION UPDATE_DATA
  UPDATE goods SET store_count = 900 WHERE goods_id = 106
  DELETE goods WHERE goods_name = '索尼D7200单反相机'
COMMIT TRANSACTION UPDATE_DATA

BEGIN TRANSACTION
INSERT INTO bookpub (书号,书名) VALUES(9,'一基础学Mysql');
SAVE TRANSACTION SavePoint
INSERT INTO bookpub (书号,书名) VALUES(8,'零基础学Oracle');
SELECT 书号,书名,作者 FROM bookpub;

ROLLBACK TRANSACTION SavePoint
SELECT 书号,书名,作者 FROM bookpub;



SQL server触发器

定义:一种特殊类型的存储过程,是一个可回滚的事务
能够:只能应用在特定的表上,对表插入、更新、删除时自动触发
不能:不能直接调用,不能执行IF,WHILE,CASE等语句

操作	inserted表			deleted表
insert	存放新增记录	 
delete						存放被删记录
update	存放更新后的记录	存放更新前的记录

格式:
go
create trigger trigger_name		     	触发器名
	on table_name                   所属表名
		[with encryption]            	是否上锁
			for[delete,insert,update]    操作类型
	as
		do sth                       触发语句
go

例子:当向表Z插值是就会读出该表中z列的值并赋给X,Y变量,再插入到XY表的x,y列中
select * from z                
select * from xy
go
create trigger trig_insert                    
	on z
		for insert
	as
		declare @x varchar(8),@y varchar(8)
		select @x=z,@y=z from inserted
		insert into xy(x,y) values(@x,@y)
go
insert into z(z) values(4)
select * from z
select * from xy
s
开始时:z表的z属性有3,4两个值,xy表的x属性有3一个值,y属性有3一个值
结束时:z表的z属性有3,4,4三个值,xy表的x属性有3,4两个值,y属笥有3,4两个值



SQL SERVER变量(GO语句中的句子视为一个整体执行)

变量声明格式:declare @变量名 类型
变量赋值格式:set @变量名=值
然后就可以应用到where语句中
go
declare @n varchar(100)
set @n =191
select * from goods where cat_id=@n
go


另外可以从表中读数据赋给变量,如下例子
注意若有多个条目,则变量最终的值是最后一个条目中的值
go
declare @id1 varchar(8),@id2 varchar(10)
select @id1=goods_id,@id2=cat_id from goods
select @id1,@id2
go


Insert picture description here

Guess you like

Origin blog.csdn.net/cj1064789374/article/details/115342173
Recommended