Amazon Q Developer는 ANSI 및 데이터베이스 관련 SQL DDL 및 DML 문을 생성할 수 있습니다. 데이터베이스 제공자가 특정 DLL 또는 DML을 구현한 경우 Amazon Q Developer가 특정 구현을 생성합니다.
주의 사항
일반적으로 Amazon Q Developer의 제안 사항이 두 개 이상인지 항상 확인하십시오.
예시 #1
Users 테이블 생성
일반적인 프롬프트
For a relational database, create the following tables using ansi sql if they do not exist:
- users
ANSI SQL 프롬프트
VSCode에서 파일을 생성하고 이름을 create_table_users_ansi.sql로 지정하고 다음 코드를 입력합니다.
/*
For a relational database, create the following tables using ansi sql if they do not exist:
- users
*/
Amazon Q Developer 제안
CREATE TABLE IF NOT EXISTS users (
id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(255) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
PRIMARY KEY (id)
);
예시 #2
Users 테이블 ALTER
Amazon Q Developer를 사용하여 열 추가, 열 수정, 인덱스 추가 등을 위한 테이블을 변경할 수 있습니다.
일반적인 프롬프트
For the users table, ALTER the table and add the following columns:
-- add unique email constraint
-- add phone number column
-- add is_student column
-- add is_admin column
-- add is_active column
-- add an index to phone number column
-- add an index to name column
ANSI SQL 프롬프트
같은 파일에서 프롬프트를 복사 붙여넣기하고 엔터를 누르면 Amazon Q Developer가 클래스에 다음 코드를 추가할 것입니다.
--
-- for the users table,alter the table and add the following columns:
-- add unique email constraint
-- add phone number column
-- add is_student column
-- add is_admin column
-- add is_active column
-- add an index to phone number column
-- add an index to name column
--
Amazon Q Developer 제안
ALTER TABLE users
ADD COLUMN phone_number VARCHAR(255) NULL,
ADD COLUMN is_student TINYINT(1) NULL,
ADD COLUMN is_admin TINYINT(1) NULL,
ADD COLUMN is_active TINYINT(1) NULL;
ALTER TABLE users
ADD UNIQUE INDEX (email);
ALTER TABLE users
ADD INDEX (phone_number);
ALTER TABLE users
ADD INDEX (name);
예시 #3
Users 테이블 트리거
Amazon Q Developer를 사용하여 테이블에 트리거를 추가할 수 있습니다.
일반적인 프롬프트
Create a trigger to update the is_active column when a user is created
ANSI SQL 프롬프트
같은 파일에서 프롬프트를 복사 붙여넣기하고 엔터를 누르면 Amazon Q Developer가 클래스에 다음 코드를 추가할 것입니다.
--
-- create a trigger to update the is_active column when a user is created
--
Amazon Q Developer 제안
테이블 트리거
CREATE TRIGGER update_is_active
AFTER
INSERT ON users
FOR EACH ROW
UPDATE users
SET is_active = 1
WHERE id = NEW.id;
예시 #4
Users 테이블에 CRUD
Amazon Q Developer를 사용하여 테이블에 CRUD(Create, Update, Read, Delete)문을 추가할 수 있습니다.
일반적인 프롬프트
/*
for the users table, create an ansi query that returns the name, and email address of all users.
for the users table, create an ansi query that returns the name, and email address of each user based on the user id.
for the users table, create an ansi query that returns the name, and email address of each user based on the email address.
for the users table, create an ansi query that returns the name, and email address of each user based on the name;
select user based on name starting with three letters and the email address ending with .com, and id greater than 100.
for the users table, select users where name starts with three letters and create_at is between two dates.
for the users table, select the top 10 most recent users.
*/
ANSI SQL 프롬프트
같은 파일에서 프롬프트를 복사 붙여넣기하고 엔터를 누르면 Amazon Q Developer가 클래스에 다음 코드를 추가할 것입니다.
/*
for the users table, create an ansi query that returns the name, and email address of all users.
for the users table, create an ansi query that returns the name, and email address of each user based on the user id.
for the users table, create an ansi query that returns the name, and email address of each user based on the email address.
for the users table, create an ansi query that returns the name, and email address of each user based on the name;
select user based on name starting with three letters and the email address ending with .com, and id greater than 100.
for the users table, select users where name starts with three letters and create_at is between two dates.
for the users table, select the top 10 most recent users.
for the users table, select the first 10 rows.
*/
Amazon Q Developer 제안
SELECT name, email FROM users;
SELECT name, email FROM users WHERE id = 1;
SELECT name, email FROM users WHERE email = 'XXXXXXXXXXXXXX';
SELECT name, email FROM users WHERE name LIKE 'XXX';
SELECT name, email FROM users WHERE name LIKE 'XXX%' AND email LIKE '%.com' AND id > 100;
SELECT name, email FROM users WHERE name LIKE 'XXX%' AND create_at BETWEEN '2020-01-01' AND '2020-01-31';
SELECT name, email FROM users ORDER BY create_at DESC LIMIT 10;
SELECT name, email FROM users LIMIT 10;