# 3.4. Importing Database Schema via CSV

## Uploading SQL Schema CSV File

Our SQL generator tool allows you to import your database schema information using a CSV file. This feature is particularly useful when you want to quickly transfer your database structure without writing DDL statements manually.

### How to Upload a SQL Schema CSV File

1. Navigate to the "Upload SQL Schema CSV File" screen in the tool.
2. You'll see a form with the following elements:
   * A text input field labeled "File Name\*"
   * An upload area with the message "Click to upload a CSV file."
   * A "Finish" button at the bottom
3. Enter a name for your file in the "File Name" field. This doesn't have to match the actual filename, but should be descriptive. For example, you might enter "customers" for a schema related to customer data.
4. Click on the upload area. This will open a file browser on your computer.
5. Select the CSV file containing your schema information.
6. Once your file is selected, it will appear in the upload area.
7. Click the "Finish" button to complete the upload process.

<figure><img src="https://3005060795-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fg9oPPpXcfNXETmlVmVUd%2Fuploads%2FhFGwKzLqRIQjEky0o71U%2Fimage.png?alt=media&#x26;token=299b66d1-6149-4e5f-91c6-b9272d1d3857" alt=""><figcaption></figcaption></figure>

### Generating the CSV File

To create the CSV file for upload, you'll need to run a query on your database to extract the schema information. Here are queries for common database systems:

#### For SQL Server

```sql
SELECT
  TABLE_SCHEMA AS [Schema],
  TABLE_NAME AS [Table],
  COLUMN_NAME AS [Column],
  DATA_TYPE AS [Type]
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  TABLE_SCHEMA = 'dbo'
```

#### For MySQL

```sql
sqlCopySELECT
  TABLE_SCHEMA AS 'Schema',
  TABLE_NAME AS 'Table',
  COLUMN_NAME AS 'Column',
  DATA_TYPE AS 'Type'
FROM
  INFORMATION_SCHEMA.COLUMNS
WHERE
  TABLE_SCHEMA = "YOUR_DATABASE_NAME"
```

Replace "YOUR\_DATABASE\_NAME" with the name of your database.

#### Steps to Generate and Prepare the CSV:

1. Run the appropriate query for your database system.
2. Export the results to a CSV file.
3. Ensure the CSV file has the following headers: `Schema,Table,Column,Type`
4. Save the file with a .csv extension.

### CSV File Format

Your CSV file should look like this:

```
CopySchema,Table,Column,Type
dbo,Customers,CustomerID,int
dbo,Customers,FirstName,varchar
dbo,Customers,LastName,varchar
dbo,Orders,OrderID,int
dbo,Orders,CustomerID,int
dbo,Orders,OrderDate,datetime
```

### Important Notes

* Ensure your CSV file contains only schema information, not actual data.
* The tool expects the CSV to have the exact column headers as shown above.
* If your database doesn't use schemas, you can leave the Schema column blank or use a placeholder value.
* Large databases may result in large CSV files. If you encounter issues, consider splitting your schema into multiple CSV files.

After uploading, you can use our tool to visualize, modify, or generate SQL from your schema. If you encounter any issues during the upload process, please check our troubleshooting guide or contact our support team.

```
This document provides clear instructions on how to use the CSV upload feature, including how to generate the necessary CSV file from different database systems. It also includes important notes and formatting requirements to ensure a smooth upload process.
```
