-
Notifications
You must be signed in to change notification settings - Fork 0
SQL
Maria Zaitseva edited this page Feb 19, 2024
·
1 revision
Below is a basic example of how you can create a table in SQL:
CREATE TABLE TableName (
column1 datatype1 [constraint],
column2 datatype2 [constraint],
...
CONSTRAINT constraint_name PRIMARY KEY (column_name),
CONSTRAINT constraint_name FOREIGN KEY (column_name) REFERENCES other_table_name(column_name)
);Explanation:
-
CREATE TABLE TableName: This is the SQL statement to create a new table namedTableName. -
(column1 datatype1 [constraint], column2 datatype2 [constraint], ...): Here you define the columns of your table along with their data types. You can also add constraints (e.g.,NOT NULL,UNIQUE, etc.) after each column definition. -
CONSTRAINT constraint_name PRIMARY KEY (column_name): This line specifies the primary key constraint for the table, ensuring uniqueness of the specified column(s). -
CONSTRAINT constraint_name FOREIGN KEY (column_name) REFERENCES other_table_name(column_name): This line creates a foreign key constraint, linking the specified column(s) to a column in another table (other_table_name).
Example:
CREATE TABLE Employees (
employee_id INT PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(100) UNIQUE,
department_id INT,
CONSTRAINT fk_department FOREIGN KEY (department_id) REFERENCES Departments(department_id)
);In this example, we are creating a table named Employees with columns employee_id, first_name, last_name, email, and department_id. employee_id is set as the primary key, email is marked as unique, and there's a foreign key constraint fk_department linking the department_id column to the department_id column in another table called Departments.
Please turn off the ad blocker to see the ad.
push(%rbp)
%rbp = %rsp
push(%r13)
push(%rax)
%rbp[-0x10] = $0x0,
%rbp[-0x10] = %r13,
%eax = 0
%edi = 0
callq 0x10f5109f0
%r13 = %rax
%rdi = %r13
main()
%rsp += $0x8
popq %r13
popq %rbp
retq