赞
踩
SQL Server和MySQL都是广泛使用的关系数据库管理系统(RDBMS),它们的SQL语法有很多相似之处,但也存在一些差异。以下是一些主要的语法区别:
CREATE DATABASE database_name;
GO
USE database_name;
GO
CREATE TABLE table_name (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
create_time DATETIME DEFAULT GETDATE()
);
CREATE DATABASE database_name;
USE database_name;
CREATE TABLE table_name (
ID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT,
create_time DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE table_name (
ID INT IDENTITY(1,1) PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
navicat
操作CREATE TABLE table_name (
ID INT AUTO_INCREMENT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
SELECT FirstName + ' ' + LastName AS FullName
FROM Employees;
SELECT CONCAT(FirstName, ' ', LastName) AS FullName
FROM Employees;
SELECT TOP 10 * FROM table_name;
SELECT * FROM table_name LIMIT 10;
SELECT GETDATE();
SELECT NOW();
IF (condition)
BEGIN
-- SQL 语句
END
ELSE
BEGIN
-- SQL 语句
END
IF condition THEN
-- SQL 语句
ELSE
-- SQL 语句
END IF;
SELECT *
FROM table_name
ORDER BY column_name
OFFSET 10 ROWS
FETCH NEXT 10 ROWS ONLY;
SELECT *
FROM table_name
ORDER BY column_name
LIMIT 10 OFFSET 10;
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE table_name
DROP COLUMN column_name;
ALTER TABLE table_name
ADD column_name datatype;
ALTER TABLE table_name
DROP COLUMN column_name;
CREATE PROCEDURE procedure_name
AS
BEGIN
-- SQL 语句
END;
EXEC procedure_name;
CREATE PROCEDURE procedure_name()
BEGIN
-- SQL 语句
END;
CALL procedure_name();
BEGIN TRANSACTION;
-- SQL 语句
COMMIT;
-- 或者
ROLLBACK;
START TRANSACTION;
-- SQL 语句
COMMIT;
-- 或者
ROLLBACK;
在SQL Server中,方括号 []
用于引用标识符(如表名、列名),特别是在这些标识符包含空格或是SQL关键字的时候。它可以避免潜在的命名冲突和错误,但不一定要使用方括号。
如果你的 sql
语句标识符没有空格,也不是SQL关键字,你可以省略方括号。
CREATE TABLE [oa_peixun_cost_detail] (
[peixun_id] VARCHAR(255) NOT NULL,
[user_name] VARCHAR(255) NOT NULL,
PRIMARY KEY ([peixun_id], [user_name])
);
CREATE TABLE [oa_peixun_cost] (
[peixun_id] VARCHAR(255) NOT NULL,
[create_user_name] VARCHAR(255) NOT NULL,
PRIMARY KEY ([peixun_id], [create_user_name])
);
CREATE TABLE [oa_peixun] (
[peixun_id] VARCHAR(255) NOT NULL,
[create_user_name] VARCHAR(255) DEFAULT NULL,
PRIMARY KEY ([peixun_id])
);
CREATE TABLE oa_peixun_cost_detail (
peixun_id VARCHAR(255) NOT NULL,
user_name VARCHAR(255) NOT NULL,
PRIMARY KEY (peixun_id, user_name)
);
CREATE TABLE oa_peixun_cost (
peixun_id VARCHAR(255) NOT NULL,
create_user_name VARCHAR(255) NOT NULL,
PRIMARY KEY (peixun_id, create_user_name)
);
CREATE TABLE oa_peixun (
peixun_id VARCHAR(255) NOT NULL,
create_user_name VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (peixun_id)
);
d VARCHAR(255) NOT NULL,
create_user_name VARCHAR(255) NOT NULL,
PRIMARY KEY (peixun_id, create_user_name)
);
CREATE TABLE oa_peixun (
peixun_id VARCHAR(255) NOT NULL,
create_user_name VARCHAR(255) DEFAULT NULL,
PRIMARY KEY (peixun_id)
);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。