Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQL: Using DEFAULT keyword to set value as autogenerated (number etc) #29

Open
tdoran opened this issue Apr 3, 2018 · 0 comments
Open

Comments

@tdoran
Copy link
Contributor

tdoran commented Apr 3, 2018

About using INSERT in SQL without using the column names and just using VALUES:
You can use the keyword DEFAULT.

Below is an example of how to do it based on the bonus round of the SQL commands challenge

INSERT INTO post_comments VALUES (DEFAULT, (SELECT id FROM
                             blog_posts WHERE text_content LIKE '%Peculiar%'), null, 3,
                             'Interesting post')

This solution is based on the first answer found here:
https://dba.stackexchange.com/questions/60521/how-are-auto-increment-keys-handled-in-insert-select-from

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant